File: ResidueChecker.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (199 lines) | stat: -rw-r--r-- 5,456 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/FORMAT/PDBFile.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/residueChecker.h>
#include <BALL/STRUCTURE/reconstructFragmentProcessor.h>

#include <BALL/FORMAT/commandlineParser.h>

#include "version.h"

using namespace std;
using namespace BALL;

int main(int argc, char* argv[])
{
	// instantiate CommandlineParser object
	CommandlineParser parpars("ResidueChecker", "check residues to debug a protein structure wrt to PDB conventions", VERSION, String(__DATE__), "ForceFields");
	parpars.registerMandatoryInputFile("pdb",  "input pdb file ");

	// TODO: offer upload of a distinguished fragDB file? 
	// shall we normalize names according to force field conventions??
	parpars.registerFlag("norm_names", "ensures a consistent naming scheme for all atoms, e.g. PDB conventions", false);

	// shall we add bonds 
	parpars.registerFlag("build_bonds", "add missing bonds", false);

	// shall we apply the fragment reconstruction
	parpars.registerFlag("frag_reconstruct", "reconstruct incomplete fragments", false);

	// an now the tests:
	parpars.registerFlag("extra_atoms", "check for extra atoms, i.e. unknown in the reference fragment", false);
	parpars.registerFlag("bond_length", "check for invalid bond length", false);
	// charges
	parpars.registerFlag("int_net_charge", "check if integer charges", false);
	parpars.registerFlag("large_charges", "check for too large charges", false);
	parpars.registerFlag("large_net_charge", "check for too large net charge", false);

	parpars.registerFlag("overlapping_atoms", "check for overlapptin atom positions", false);
	parpars.registerFlag("nan_positions", "check for ill-valued atomic positions", false);
	parpars.registerFlag("elements", "check if atom names reflect the atomic element", false);
	parpars.registerFlag("dublicate_atom_names", "check for dublicated atom names", false);
	parpars.registerFlag("unknown_residues", "check for unknown residues", false);

	//TODO: offer write Logs to a pdf

	// the manual
	String man = String("This tool checks the residues of a pdb file wrt. common inconsistencies such as missing atoms or suspicious distances.");

	parpars.setToolManual(man);

	parpars.setSupportedFormats("pdb", "pdb");

	// parse the command line
	parpars.parse(argc, argv);

	bool norm_names = false;
	if (parpars.has("norm_names"))
	{
		norm_names  = parpars.get("norm_names").toBool();
	}

	bool build_bonds = false;
	if (parpars.has("build_bonds"))
	{
		build_bonds = parpars.get("build_bonds").toBool();
	}

	bool frag_reconstruct = false;
	if (parpars.has("frag_reconstruct"))
	{
		frag_reconstruct = parpars.get("frag_reconstruct").toBool();
	}

	PDBFile pdb;
	pdb.open(parpars.get("pdb"), std::ios::in);
	if (!pdb)
	{
		// if file does not exist: complain and abort
		Log.error() << "error opening " << parpars.get("pdb") << " for input." << std::endl;
		exit(2);
	}

	System sys;
	pdb >> sys;
	pdb.close();

	bool changes = false;

	// normalize the names and build all bonds
	FragmentDB db("");

	if (norm_names)
	{
		sys.apply(db.normalize_names);
		changes = true;
	}

	if (build_bonds)
	{
		sys.apply(db.build_bonds);
		changes = true;
	}

	if (frag_reconstruct)
	{
		ReconstructFragmentProcessor proc(db);
		sys.apply(proc);
		sys.apply(db.build_bonds);
		changes = true;
	}

	// now specify the ResidueChecker
	ResidueChecker check(db);

	//MISSING_ATOMS
	if (parpars.has("missing_atoms"))
	{
		check.enable(ResidueChecker::MISSING_ATOMS, parpars.get("missing_atoms").toBool());
	}

	//EXTRA_ATOMS
	if (parpars.has("extra_atoms"))
	{
		check.enable(ResidueChecker::EXTRA_ATOMS, parpars.get("extra_atoms").toBool());
	}

	// ELEMENTS, 	
	if (parpars.has("elements"))
	{
		check.enable(ResidueChecker::ELEMENTS, parpars.get("elements").toBool());
	}

	// SUSPECT_BOND_LENGTHS, 
	if (parpars.has("bond_length"))
	{
		check.enable(ResidueChecker::SUSPECT_BOND_LENGTHS, parpars.get("bond_length").toBool());
	}

  // NON_INTEGRAL_NET_CHARGE, //TODO: meaning reasonable or integer ??
	if (parpars.has("net_charge"))
	{
		check.enable(ResidueChecker::NON_INTEGRAL_NET_CHARGE, parpars.get("net_charge").toBool());
	}

	// LARGE_CHARGES, 	
	if (parpars.has("large_charges"))
	{
		check.enable(ResidueChecker::LARGE_CHARGES, parpars.get("large_charges").toBool());
	}

	// LARGE_NET_CHARGE, 
	if (parpars.has("large_net_charge"))
	{
		check.enable(ResidueChecker::LARGE_NET_CHARGE, parpars.get("large_net_charge").toBool());
	}

	// NAN_POSITIONS, 
	if (parpars.has("nan_positions"))
	{
		check.enable(ResidueChecker::NAN_POSITIONS, parpars.get("nan_positions").toBool());
	}

  // OVERLAPPING_ATOMS,
	if (parpars.has("overlapping_atoms"))
	{
		check.enable(ResidueChecker::OVERLAPPING_ATOMS, parpars.get("overlapping_atoms").toBool());
		check.enable(ResidueChecker::STRONGLY_OVERLAPPING_ATOMS, parpars.get("overlapping_atoms").toBool());
	}

	// DUPLICATE_ATOM_NAMES, 
	if (parpars.has("dublicate_atom_names"))
	{
		check.enable(ResidueChecker::DUPLICATE_ATOM_NAMES, parpars.get("dublicate_atom_names").toBool());
	}

	// UNKNOWN_RESIDUES, 
	if (parpars.has("unknown_residues"))
	{
		check.enable(ResidueChecker::UNKNOWN_RESIDUES, parpars.get("unknown_residues").toBool());
	}


	// set specified tests
	sys.apply(check);

	// overwrite
	if (changes)
	{
		pdb.open(parpars.get("pdb"), ios::out);
		pdb << sys;
		pdb.close();
		Log << "changes are written " <<  std::endl;
	}

	return 0;
}