File: compareForces.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-- 2,002 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:
//
// $Id: compareForces.C,v 1.1.4.1 2007/03/25 21:32:21 oliver Exp $
//
// test program for the MMFF94 implementation

#include <BALL/common.h>

#include <BALL/DATATYPE/string.h>
#include <BALL/MATHS/vector3.h>
#include <BALL/FORMAT/lineBasedFile.h>

#include <cmath>

using namespace std;
using namespace BALL;

String dir;

Size wrong_types = 0;
File* out = 0;

float diff(double original, double our)
{
	double x = original - our;
	x = fabs(x);
	if (x < 0.05) return 0;
	return x / fabs(original);
}

int main(int argc, char** argv)
{
	vector<Vector3> charmm_forces, ball_forces;

	vector<String> names;

	LineBasedFile clf("charmm.out");
	while(clf.readLine())
	{
		vector<String> fields;
		if (clf.getLine().split(fields) != 10)
		{
			Log.error() << "Not enough fields!" << std::endl;
			return 0;
		}

		Vector3 v(fields[4].toFloat(),
							fields[5].toFloat(),
							fields[6].toFloat());

		charmm_forces.push_back(-v);
	}

	LineBasedFile blf("BALL.out");
	while(blf.readLine())
	{
		vector<String> fields;
		if (blf.getLine().split(fields) != 4)
		{
			Log.error() << "Not enough fields!" << std::endl;
			return 0;
		}

		Vector3 v(fields[1].toFloat(),
							fields[2].toFloat(),
							fields[3].toFloat());

		names.push_back(fields[0]);

		ball_forces.push_back(v);
	}

	if (charmm_forces.size() != ball_forces.size())
	{
		Log.error() << "Different number of atoms!" << std::endl;
		return 0;
	}

	Log.precision(3);
	float max_diff = 0.01;
	for (Position p = 0; p < charmm_forces.size(); p++)
	{
		float d = std::max(std::max(diff(charmm_forces[p].x, ball_forces[p].x),
												diff(charmm_forces[p].y, ball_forces[p].y)),
												diff(charmm_forces[p].z, ball_forces[p].z));

		if (d > max_diff)
		{
			String s(d);
			s.truncate(4);
			Log.error() << "*** " << names[p] << ": ******** " << s << std::endl 
				          << charmm_forces[p] << std::endl
				          << ball_forces[p] << std::endl;
		}
	}

	return 0;
}