1
/**********************************************************************
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
***********************************************************************/
19
// Simple programmable atom typer
21
// Usage is in sample main below
25
void patty::read_rules(const string &infile)
27
ifstream ifs, ifs1, *ifsP;
29
char buffer[BUFF_SIZE];
30
char tmp_str[BUFF_SIZE];
31
char patty_dir[BUFF_SIZE];
35
ifs.open(infile.c_str());
39
if (getenv("BABEL_DATADIR") == NULL)
41
cerr << "The BABEL_DATADIR environment variable is not defined" << endl;
42
cerr << "Please define it so the program can find " << infile << endl;
46
strcpy(patty_dir,getenv("BABEL_DATADIR"));
47
strcat(patty_dir,FILE_SEP_CHAR);
48
strcat(patty_dir,infile.c_str());
53
// cerr << "Could not open " << patty_dir << endl;
60
cerr << "Could not open " << patty_dir << endl;
63
while (ifsP->getline(buffer,BUFF_SIZE))
67
tokenize(vs,buffer," \t\n");
70
strcpy(tmp_str,vs[0].c_str());
71
_sp[i]->Init(tmp_str);
72
smarts.push_back(vs[0]);
81
void patty::assign_rules(vector<string> &rules)
84
char buffer[BUFF_SIZE];
85
char tmp_str[BUFF_SIZE];
89
for ( i = 0 ; i < rules.size() ; i++ )
91
strncpy(buffer, rules[i].c_str(), BUFF_SIZE);
94
tokenize(vs,buffer," \t\n");
97
strcpy(tmp_str,vs[0].c_str());
98
_sp[i]->Init(tmp_str);
99
smarts.push_back(vs[0]);
100
typ.push_back(vs[1]);
111
void patty::assign_types(OBMol &mol,vector<string> &atm_typ)
113
atm_typ.resize(mol.NumAtoms()+1);
115
for (unsigned int i = 0; i < _sp.size(); i++)
118
vector<vector<int> > match = _sp[i]->GetMapList();
119
//vector<vector<int> >& match = _sp[i]->GetMapList();
123
cout << typ[i] << " " << smarts[i] << " matched " ;
125
for (unsigned int j = 0; j < match.size(); j++)
128
cout << match[j][0] << " ";
129
atm_typ[match[j][0]] = typ[i];
137
void patty::assign_types(OBMol &mol,vector<int> &atm_typ)
139
atm_typ.resize(mol.NumAtoms()+1);
141
for (unsigned int i = 0; i < _sp.size(); i++)
144
vector<vector<int> > match = _sp[i]->GetMapList();
145
//vector<vector<int> >& match = _sp[i]->GetMapList();
149
cout << typ[i] << " " << smarts[i] << " matched " ;
151
for (unsigned int j = 0; j < match.size(); j++)
154
cout << match[j][0] << " ";
155
atm_typ[match[j][0]] = type_to_int(typ[i]);
164
int patty::type_to_int(const string &type, bool failOnUndefined)
170
switch(toupper(type.c_str()[0]))
172
case 'C' : // CAT - CATION
176
if (toupper(type.c_str()[1]) == 'N') // ANI - ANION
179
result = PT_ACCEPTOR;
181
case 'P' : // POL - POLAR
184
case 'D' : // DON - DONOR
187
case 'H' : // HYD - HYDROPHOBIC
188
result = PT_HYDROPHOBIC;
193
case 'O' : // OTH - OTHER
197
// This was added by Brian,
198
// Behavior will fail if type is undefined
199
if (failOnUndefined){
200
cerr << "Unable to find type of feature passed in " << endl;
201
cerr << "Feature passed in is " << type << endl;
212
#ifdef I_EVER_BUY_A_MICHAEL_BOLTON_ALBUM
214
int main(int argc, char *argv[])
217
vector<string> types;
219
ifstream ifs(argv[1]);
222
cerr << "Could not open argv[1] " << endl;
226
patty p("simple.txt");
230
if (!mol.NumAtoms()) break;
231
p.assign_types(mol,types);
235
for (int i = 1; i < types.size(); i++)
237
cout << i << " " << types[i] << endl;