$darkmode
DENOPTIM
TinkerMolecule.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.integration.tinker;
21
22import java.util.ArrayList;
23
24
30public class TinkerMolecule implements Cloneable
31{
32 private ArrayList<TinkerAtom> lstAtoms;
33 ArrayList<int[]> zdel;
34 ArrayList<int[]> zadd;
35 String molName;
36
37 private boolean debug = false;
38
39//------------------------------------------------------------------------------
40
42 {
43 lstAtoms = new ArrayList<TinkerAtom>();
44 zdel = new ArrayList<int[]>();
45 zadd = new ArrayList<int[]>();
46 molName = "";
47 }
48
49//------------------------------------------------------------------------------
50
51 public TinkerMolecule(String molName, ArrayList<int[]> zadd,
52 ArrayList<int[]> zdel, ArrayList<TinkerAtom> lstAtoms)
53 {
54 this.lstAtoms = lstAtoms;
55 this.molName = molName;
56 this.zdel = zdel;
57 this.zadd = zadd;
58 }
59
60//------------------------------------------------------------------------------
61
70 public ArrayList<Integer> getConnectedAtoms(int pos)
71 {
72 ArrayList<Integer> lst = new ArrayList<>();
73
74 TinkerAtom tatm = getAtom(pos);
75 int[] d = tatm.getAtomNeighbours();
76 if (d[0] != 0)
77 lst.add(Integer.valueOf(d[0]));
78
79 int numberOfAtoms = lstAtoms.size();
80 for (int i = 0; i<numberOfAtoms; i++)
81 {
82 tatm = lstAtoms.get(i);
83 if (tatm.getXYZIndex() == pos)
84 {
85 continue;
86 }
87 d = tatm.getAtomNeighbours();
88 if (d[0] == pos)
89 {
90 lst.add(Integer.valueOf(tatm.getXYZIndex()));
91 }
92 }
93
94
95 return lst;
96 }
97
98//------------------------------------------------------------------------------
99
105 public void set3DCoordinates(ArrayList<double[]> coords)
106 {
107 int numberOfAtoms = coords.size();
108 for (int i = 0; i<numberOfAtoms; i++)
109 {
110 TinkerAtom atom = lstAtoms.get(i);
111 double[] x = coords.get(i);
112 atom.moveTo(x);
113 }
114 }
115
116//------------------------------------------------------------------------------
117
118 public void setName(String molName)
119 {
120 this.molName = molName;
121 }
122
123//------------------------------------------------------------------------------
124
125 public void setAtoms(ArrayList<TinkerAtom> lstAtoms)
126 {
127 this.lstAtoms = lstAtoms;
128 }
129
130//------------------------------------------------------------------------------
131
132 public void setBondPairs(ArrayList<int[]> zdel, ArrayList<int[]> zadd)
133 {
134 this.zdel = zdel;
135 this.zadd = zadd;
136 }
137
138//------------------------------------------------------------------------------
139
140 public ArrayList<TinkerAtom> getAtoms()
141 {
142 return this.lstAtoms;
143 }
144
145//------------------------------------------------------------------------------
146
147 public int getLastAtomNumber()
148 {
149 return lstAtoms.get(lstAtoms.size()-1).getXYZIndex();
150 }
151
152//------------------------------------------------------------------------------
153
154 public String getName()
155 {
156 return this.molName;
157 }
158
159//------------------------------------------------------------------------------
160
161 public ArrayList<int[]> getBondAdd()
162 {
163 return this.zadd;
164 }
165
166//------------------------------------------------------------------------------
167
168 public ArrayList<int[]> getBondDel()
169 {
170 return this.zdel;
171 }
172
173//------------------------------------------------------------------------------
174
181 public TinkerAtom getAtom(int pos)
182 {
183 for (int i=0; i<lstAtoms.size(); i++)
184 {
185 TinkerAtom atm = lstAtoms.get(i);
186 if (atm.getXYZIndex() == pos)
187 {
188 return atm;
189 }
190 }
191 return null;
192 }
193
194//------------------------------------------------------------------------------
195
199 @Override
200 public Object clone() throws CloneNotSupportedException
201 {
202 return super.clone();
203 }
204
205//------------------------------------------------------------------------------
206
211 {
212 String nMolName = this.molName;
213 ArrayList<TinkerAtom> atms = new ArrayList<TinkerAtom>();
214 for (int ia=0; ia<this.lstAtoms.size(); ia++)
215 {
216 TinkerAtom oTa = this.lstAtoms.get(ia);
217 String str = oTa.getAtomString();
218 int at = oTa.getAtomType();
219 double[] oXyz = oTa.getXYZ();
220 double[] nXyz = new double[] {oXyz[0], oXyz[1], oXyz[2]};
221 int[] oNBnd = oTa.getAtomNeighbours();
222 int[] nNBnd = new int[] {oNBnd[0], oNBnd[1], oNBnd[2], oNBnd[3]};
223 double[] oDiAng = oTa.getDistAngle();
224 double[] nDiAng = new double[] {oDiAng[0], oDiAng[1], oDiAng[2]};
225 TinkerAtom nTa = new TinkerAtom(ia+1,str,at,nXyz,nNBnd,nDiAng);
226 long vId = oTa.getVertexId();
227 nTa.setVertexId(vId);
228 atms.add(nTa);
229 }
230
231 ArrayList<int[]> zadd = new ArrayList<int[]>();
232 for (int ia=0; ia<this.zadd.size(); ia++)
233 {
234 int[] oBnd = this.zadd.get(ia);
235 int[] nBnd = new int [] {oBnd[0], oBnd[1]};
236 zadd.add(nBnd);
237 }
238
239 ArrayList<int[]> zdel = new ArrayList<int[]>();
240 for (int ia=0; ia<this.zdel.size(); ia++)
241 {
242 int[] oBnd = this.zdel.get(ia);
243 int[] nBnd = new int [] {oBnd[0], oBnd[1]};
244 zdel.add(nBnd);
245 }
246
247 TinkerMolecule nTMol = new TinkerMolecule(nMolName, zadd, zdel, atms);
248
249 return nTMol;
250 }
251
252//------------------------------------------------------------------------------
253
254 public boolean isConnected(int atm1, int atm2)
255 {
256 TinkerAtom A1 = getAtom(atm1);
257 TinkerAtom A2 = getAtom(atm2);
258
259 int[] d1 = A1.getAtomNeighbours();
260 int[] d2 = A2.getAtomNeighbours();
261
262 if (d1[0] == atm2)
263 return true;
264 if (d2[0] == atm1)
265 return true;
266
267 return false;
268 }
269
270//------------------------------------------------------------------------------
271
272 public void addMolecule(TinkerMolecule tmol2)
273 {
274 lstAtoms.addAll(tmol2.getAtoms());
275
276 // add zdel, zadd
277 zadd.addAll(tmol2.getBondAdd());
278 zdel.addAll(tmol2.getBondDel());
279 }
280
281//------------------------------------------------------------------------------
282
287 public void addAtom(TinkerAtom ta)
288 {
289 lstAtoms.add(ta);
290 }
291
292//------------------------------------------------------------------------------
299 public void addBond(int a1, int a2)
300 {
301 int[] newBnd = new int[2];
302 newBnd[0] = a1;
303 newBnd[1] = a2;
304 zadd.add(newBnd);
305 }
306
307//------------------------------------------------------------------------------
308
316 public boolean isTorsionUsed(int t1, int t2)
317 {
318 for (TinkerAtom atm : lstAtoms)
319 {
320 int[] nbs = atm.getAtomNeighbours();
321
322 if ((nbs[0] == t1) && (nbs[1] == t2) && atm.usesProperTorsion())
323 {
324 if (debug)
325 System.err.println("Already used atoms(a): " + t1 + " " + t2);
326 return true;
327 }
328 else if ((nbs[0] == t2) && (nbs[1] == t1)
329 && atm.usesProperTorsion())
330 {
331 if (debug)
332 System.err.println("Already used atoms(b): " + t2 + " " + t1);
333 return true;
334 }
335 }
336 return false;
337 }
338
339//------------------------------------------------------------------------------
340
341 public void printIC()
342 {
343 int numatoms = lstAtoms.size();
344 // write out the number of atoms and the title
345 String line = "";
346 line = String.format("%6d %s%n", numatoms, molName);
347 System.err.print(line);
348
349 for (int i = 0; i<numatoms; i++)
350 {
351 TinkerAtom atom = lstAtoms.get(i);
352 int[] d1 = atom.getAtomNeighbours();
353 double[] d2 = atom.getDistAngle();
354 // output of first three atoms is handled separately
355 if (i==0)
356 {
357 line = String.format("%6d %-3s%6d%n",
358 atom.getXYZIndex(), atom.getAtomString(),
359 atom.getAtomType());
360 System.err.print(line);
361 }
362 else if (i == 1)
363 {
364 line = String.format("%6d %-3s%6d%6d%10.5f%n",
365 atom.getXYZIndex(), atom.getAtomString(),
366 atom.getAtomType(), d1[0], d2[0]);
367 System.err.print(line);
368 }
369 else if (i == 2)
370 {
371 line = String.format("%6d %-3s%6d%6d%10.5f%6d%10.4f%n",
372 atom.getXYZIndex(), atom.getAtomString(),
373 atom.getAtomType(), d1[0], d2[0],
374 d1[1], d2[1]);
375 System.err.print(line);
376 }
377 // output the fourth through final atoms
378 else
379 {
380 line = String.format("%6d %-3s%6d%6d%10.5f%6d%10.4f%6d%10.4f%6d%n",
381 atom.getXYZIndex(), atom.getAtomString(),
382 atom.getAtomType(), d1[0], d2[0],
383 d1[1], d2[1], d1[2], d2[2], d1[3]);
384 System.err.print(line);
385 }
386 }
387
388// if (zadd.size() > 0 || zdel.size() > 0)
389// {
390// line = "\n";
391// System.err.print(line);
392//
393// for (int i=0; i<zadd.size(); i++)
394// {
395// int[] z = zadd.get(i);
396// line = String.format("%6d%6d%n", z[0], z[1]);
397// System.err.println(line);
398// }
399//
400// if (zdel.size() > 0)
401// {
402// line = "\n";
403// System.err.print(line);
404//
405// for (int i=0; i<zdel.size(); i++)
406// {
407// int[] z = zdel.get(i);
408// line = String.format("%6d%6d%n", z[0], z[1]);
409// System.err.println(line);
410// }
411// }
412// }
413
414 System.err.println();
415 }
416
417//------------------------------------------------------------------------------
418
419
420}
Based on the code from ffx.kenai.com Michael J.
Definition: TinkerAtom.java:26
int getXYZIndex()
Gets the XYZ Index.
void moveTo(double[] d)
Add a vector to the Atom's current position vector.
void set3DCoordinates(ArrayList< double[]> coords)
store 3d coordinates of the fragments
ArrayList< Integer > getConnectedAtoms(int pos)
Identify the list of connected atoms (only first neighbours are considered) to the atom at the specif...
TinkerMolecule deepCopy()
This method produces a deep copy of the object.
void addBond(int a1, int a2)
Add one bond by appending a pair of indeces into the z-add section.
TinkerAtom getAtom(int pos)
Returns the atom which has the XYZ index set to pos.
void addAtom(TinkerAtom ta)
Add one atom to this molecule.
void setAtoms(ArrayList< TinkerAtom > lstAtoms)
void setBondPairs(ArrayList< int[]> zdel, ArrayList< int[]> zadd)
boolean isTorsionUsed(int t1, int t2)
Check if the pair of atoms has been used to define a proper torsion.
Object clone()
This method produces a shallow copy of the object.
TinkerMolecule(String molName, ArrayList< int[]> zadd, ArrayList< int[]> zdel, ArrayList< TinkerAtom > lstAtoms)