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
static bool WriteChem3d(ostream &ofs,OEMol &mol, char *mol_typ);
21
bool WriteChem3d2(ostream &ofs,OEMol &mol)
23
return(WriteChem3d(ofs,mol,"C3D"));
26
bool WriteChem3d1(ostream &ofs,OEMol &mol)
28
return(WriteChem3d(ofs,mol,"MM2"));
31
bool WriteMmads(ostream &ofs,OEMol &mol)
33
return(WriteChem3d(ofs,mol,"MMADS"));
36
static bool WriteChem3d(ostream &ofs,OEMol &mol, char *mol_typ)
40
char buffer[BUFF_SIZE],type_name[10],ele_type[10];
42
sprintf(buffer,"%d",mol.NumAtoms()); ofs << buffer;
43
if (EQ(mol_typ,"MMADS"))
45
sprintf(buffer," %s",mol.GetTitle()); ofs << buffer;
46
ttab.SetToType("MM2");
48
else ttab.SetToType(mol_typ);
51
ttab.SetFromType("INT");
54
vector<OEAtom*>::iterator i;
55
vector<OEBond*>::iterator j;
57
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
59
if (!ttab.Translate(type_name,atom->GetType()))
61
sprintf(buffer,"Unable to assign %s type to atom %d type = %s\n",
62
mol_typ,atom->GetIdx(),atom->GetType());
64
atnum = atom->GetAtomicNum();
65
type_num = atnum * 10 + atom->GetValence();
66
sprintf(type_name,"%d",type_num);
68
strcpy(ele_type,etab.GetSymbol(atom->GetAtomicNum()));
69
sprintf(buffer,"%-3s %-5d %8.4f %8.4f %8.4f %5s",
75
type_name); ofs << buffer;
77
for (nbr = atom->BeginNbrAtom(j);nbr;nbr = atom->NextNbrAtom(j))
79
sprintf(buffer,"%6d",nbr->GetIdx());
87
static bool ReadChem3d(istream&,OEMol&,bool,char*);
89
bool ReadMmads(istream &ifs,OEMol &mol,char *title)
91
return(ReadChem3d(ifs,mol,true,"MM2"));
94
bool ReadChem3d1(istream &ifs,OEMol &mol,char *title)
96
return(ReadChem3d(ifs,mol,false,"MM2"));
99
int read_chem3d2(istream &ifs,OEMol &mol,char *title)
101
return(ReadChem3d(ifs,mol,false,"C3D"));
104
bool ReadChem3d(istream &ifs,OEMol &mol,bool mmads,char *type_key)
106
char buffer[BUFF_SIZE];
108
char tmp[10],tmp1[10];
109
char atomic_type[10];
110
float exponent = 0.0f;
111
float divisor = 1.0f;
112
float Alpha,Beta,Gamma,A,B,C;
113
bool has_fractional = false, has_divisor = false;
117
ifs.getline(buffer,BUFF_SIZE);
122
if (vs.empty()) return(false);
123
natoms = atoi((char*)vs[0].c_str());
124
if (vs.size() == 2) mol.SetTitle(vs[1]);
131
sscanf(buffer,"%d%f%f%f%f%f%f",
132
&natoms,&Alpha,&Beta,&Gamma,&A,&B,&C);
133
m.FillOrth(Alpha,Beta,Gamma,A,B,C);
134
has_fractional = true;
137
sscanf(buffer,"%d%f%f%f%f%f%f%f",
138
&natoms,&Alpha,&Beta,&Gamma,&A,&B,&C,&exponent);
139
m.FillOrth(Alpha,Beta,Gamma,A,B,C);
140
has_fractional = true;
144
sscanf(buffer,"%d",&natoms);
149
if (!natoms) return(false);
150
divisor = pow(10.0,exponent);
151
mol.ReserveAtoms(natoms);
153
ttab.SetToType("INT");
154
ttab.SetFromType(type_key);
161
for (i = 1; i <= natoms; i++)
163
ifs.getline(buffer,BUFF_SIZE);
164
sscanf(buffer,"%s%*d%f%f%f%s",
171
if (has_fractional) v *= m;
172
if (has_divisor) v/= divisor;
175
if (vs.empty()) return(false);
177
atom = mol.NewAtom();
178
ttab.Translate(tmp1,tmp);
181
atom->SetAtomicNum(etab.GetAtomicNum(atomic_type));
183
for (k = 6;k < vs.size(); k++)
184
mol.AddBond(atom->GetIdx(),atoi((char*)vs[k].c_str()),1);
187
//assign_bond_order(mol);