File: add_hydrogens.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 (118 lines) | stat: -rw-r--r-- 2,894 bytes parent folder | download | duplicates (8)
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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

// A small program for adding hydrogens to a PDB file (which usually comes
// without hydrogen information) and minimizing all hydrogens by means of a
// StrangLBFGS minimizer.

#include <BALL/KERNEL/system.h>
#include <BALL/KERNEL/selector.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/MOLMEC/AMBER/amber.h>
#include <BALL/MOLMEC/MINIMIZATION/conjugateGradient.h>
#include <BALL/MOLMEC/MINIMIZATION/steepestDescent.h>
#include <BALL/MOLMEC/MINIMIZATION/strangLBFGS.h>
#include <BALL/MOLMEC/MINIMIZATION/shiftedLVMM.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/residueChecker.h>
#include <BALL/DATATYPE/string.h>
#include <BALL/SYSTEM/path.h>

using namespace std;
using namespace BALL;

int main(int argc, char** argv)
{
	if ((argc < 3) || (argc > 4))
	{
		Log << "Usage:" << argv[0] << " <PDB infile> <PDB outfile> [<amber parameter file>]" << endl;
		return 1;
	}

	Log << "Loading " << argv[1] << "..." << endl;
	PDBFile infile(argv[1]);
	if (!infile)
	{
		// if file does not exist: complain and abort
		Log.error() << "error opening " << argv[1] << " for input." << endl;
		return 2;
	}

	System system;
	infile >> system;
	Log << "done." << endl;

	Log << "Initializing FragmentDB..." << endl;
	FragmentDB db("");
	Log << "done." << endl;

	Log << "Normalizing names..." << endl;
	system.apply(db.normalize_names);
	Log << "done." << endl;
	
	Log << "Adding hydrogens..." << endl;
	system.apply(db.add_hydrogens);
	Log << "  ...added " << db.add_hydrogens.getNumberOfInsertedAtoms() 
			<< " atoms" << endl;
	Log << "done." << endl;

	Log << "Building Bonds..." << endl;
	system.apply(db.build_bonds);
	Log << "done." << endl;
	

	Log << "Applying ResidueChecker..." << endl << endl;
	ResidueChecker check;
	system.apply(check);
	Log << "done." << endl;

	Log << "Initializing force field..." << endl;
	AmberFF amber_ff;
	if (argc == 4)
	{
		Path path;
		String tmp = path.find(argv[3]);
		if (tmp == "") tmp = argv[3];
		amber_ff.options.set(AmberFF::Option::FILENAME, tmp);
	}
	amber_ff.setup(system);
	Log << "done." << endl;
	Log << "Selecting H atoms..." << endl;
	Selector h_select("element(H)");
	system.apply(h_select);
	Log << "done." << endl;
	Log << "Starting minimizer: " << endl << endl;
	
	// We choose the L-BFGS minimizer
	
	/*
	SteepestDescentMinimizer sdm(amber_ff);
	sdm.setEnergyOutputFrequency(1);
	sdm.minimize(1000);
	*/
	
	/*
	ConjugateGradientMinimizer cgm(amber_ff);
	cgm.setEnergyOutputFrequency(1);
	cgm.minimize(1000);
	*/
	
	/*
	ShiftedLVMMMinimizer sm(amber_ff);
	sm.setEnergyOutputFrequency(1);
	sm.minimize(1000);
	*/
	
	StrangLBFGSMinimizer bfgsm(amber_ff);
	bfgsm.setEnergyOutputFrequency(1);
	bfgsm.minimize(1000);
	
	Log << "Writing " << argv[2] << "..." << endl;
	PDBFile outfile(argv[2], std::ios::out);
	outfile << system;
	Log << "done." << endl;

	return 0;
}