-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharges.cpp
More file actions
69 lines (59 loc) · 1.59 KB
/
charges.cpp
File metadata and controls
69 lines (59 loc) · 1.59 KB
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
#include "charges.h"
Charges::Charges(const Input &input,const GroFile &gro) :
type(gro.getType()), res(gro.getRes()), resnum(gro.getResNum())
{
printf("Reading itp files and finding Charges...\n");
//read all itp files
int nITP=input.getNitp();
std::vector<ItpFile> itps;
for (int ii=0; ii<nITP; ii++)
itps.push_back(ItpFile(input.getITPfile(ii)));
//find charges for each atom in gro
natom = gro.getNatom();
charges = new float[natom];
cg = new int[natom];
string tmptype,tmpres;
int ii,jj,tmpresnum,cgThis;
int thisI = -1;
int cgLast = -1;
int itpLast = -1;
int lastI = -1;
nCG=-1;
for (ii=0; ii<natom; ii++) {
//loop through itp files to find charge
tmptype = type[ii];
tmpres = res[ii];
tmpresnum = resnum[ii];
for (jj=0; jj<nITP; jj++) {
thisI=itps[jj].findType(tmpresnum, tmptype, tmpres);
if (thisI >= 0) {
charges[ii]=itps[jj].getQ(thisI);
break;
}
}
//test that jj==nITP for failure
if (jj==nITP) {
printf("ERROR: no charge found for %d%s: %s\n",
tmpresnum, tmpres.c_str(), tmptype.c_str());
exit(EXIT_FAILURE);
}
cgThis=itps[jj].getCG(thisI);
//last test is necessary for water, which uses same itp file over and over
if (cgLast!=cgThis || itpLast!=jj ||
(tmpres.compare("SOL")==0 && itpLast==jj && thisI-lastI!=1)) {
cgSt.push_back(ii);
cgLast=cgThis;
itpLast=jj;
cg[ii]=++nCG;
} else
cg[ii]=nCG;
lastI=thisI;
}
nCG++;
//add end of last cg
cgSt.push_back(ii);
}
Charges::~Charges() {
delete[] charges;
delete[] cg;
}