File: AddMissingAtoms.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 (99 lines) | stat: -rw-r--r-- 3,136 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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/FORMAT/molFileFactory.h>
#include <BALL/FORMAT/commandlineParser.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/MOLMEC/AMBER/amber.h>
#include <BALL/MOLMEC/MINIMIZATION/conjugateGradient.h>
#include <BALL/MOLMEC/COMMON/assignTypes.h>
#include <BALL/KERNEL/selector.h>
#include <BALL/STRUCTURE/defaultProcessors.h>
#include <BALL/STRUCTURE/residueChecker.h>
#include <BALL/STRUCTURE/fragmentDB.h>

#include "version.h"

using namespace BALL;
using namespace std;

int main(int argc, char* argv[])
{
	CommandlineParser parpars("AddMissingAtoms", "add missing atoms to protein structures", VERSION, String(__DATE__), "Preparation");
	parpars.registerMandatoryInputFile("i", "input file");
	parpars.registerMandatoryOutputFile("o", "output file");

	parpars.setSupportedFormats("i","pdb");
	parpars.setSupportedFormats("o","pdb,drf");

	parpars.registerFlag("opt_hyd", "optimize the positions of hydrogens", false);

	String manual = "AddMissingAtoms tool allows you to missing atoms, i.e. hydrogens to a protein structure.\n\n Optional parameter is the optimize_hydrogens flag (-opt_hyd), which uses the AMBER force field to run a quick energy minization for all hydrogen atoms.\n\nOutput of this tool is one pdb-file containing the input protein structure with added atoms.";
	parpars.setToolManual(manual);

	parpars.parse(argc, argv);

	PDBFile input(parpars.get("i"), ios::in);
	//GenericMolFile* input = MolFileFactory::open(parpars.get("i"), ios::in);
	//PDBFile* pdb_input = dynamic_cast<PDBFile*>(input);
	if (!input)
	{
		Log.error() << "Cannot open PDB input file " << parpars.get("i") << endl;
		return 2;
	}

	System S;
	input >> S;
	input.close();

	FragmentDB fragdb("");

	Log.disableOutput();
	S.apply(fragdb.normalize_names);
	S.apply(fragdb.add_hydrogens);
	S.apply(fragdb.build_bonds);
	Log.enableOutput();

	if (parpars.has("opt_hyd") && parpars.get("opt_hyd").toBool())
	{
		AmberFF FF;

		// we then select all hydrogens (element(H))
		// using a specialized processor (Selector)
		S.deselect();
		FF.setup(S);
		Selector selector("element(H)");
		S.apply(selector);

		// now we create a minimizer object that uses a conjugate 
		// gradient algorithm to optimize the atom positions
		ConjugateGradientMinimizer minimizer;

		// calculate the total energy of the system
		float initial_energy = FF.updateEnergy();
		Log << "initial energy: " << initial_energy << " kJ/mol" << endl;

		// initialize the minimizer and perform (up to)
		// 1000 optimization steps
		minimizer.setup(FF);
		minimizer.setEnergyOutputFrequency(1);
		minimizer.minimize(50);

		// calculate the terminal energy and print it
		float terminal_energy = FF.getEnergy();

		Log << "energy before/after minimization: " << initial_energy << "/" << terminal_energy << " kJ/mol" << endl;
	}

	// write the optimized structure to a file whose
	// name is given as the second command line argument
	String outfile_name = String(parpars.get("o"));
	PDBFile outfile(outfile_name, ios::out);
	outfile << S;
	outfile.close();

	Log << "wrote file " << outfile_name << endl;
}