Skip to content

Commit 604d348

Browse files
committed
Fix AtomTools method.
1 parent 407485a commit 604d348

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

misc/extra/src/main/java/org/openscience/cdk/geometry/AtomTools.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,31 +406,31 @@ public static Point3d[] calculate3DCoordinates2(Point3d aPoint, Point3d bPoint,
406406
* (i) 1 points required; if A, B, C, D coplanar, no points.
407407
* else vector is resultant of BA, CA, DA
408408
*
409-
* @param aPoint to which substituents are added
410-
* @param bPoint first ligand of A
411-
* @param cPoint second ligand of A
412-
* @param dPoint third ligand of A
409+
* @param focus to which substituents are added
410+
* @param aNbor first ligand of A
411+
* @param bNbor second ligand of A
412+
* @param cNbor third ligand of A
413413
* @param length A-X length
414414
*
415415
* @return Point3d nwanted points (or null if failed (coplanar))
416416
*/
417-
public static Point3d calculate3DCoordinates3(Point3d aPoint, Point3d bPoint, Point3d cPoint, Point3d dPoint,
417+
public static Point3d calculate3DCoordinates3(Point3d focus, Point3d aNbor, Point3d bNbor, Point3d cNbor,
418418
double length) {
419-
Vector3d v1 = new Vector3d(aPoint);
420-
v1.sub(bPoint);
421-
Vector3d v2 = new Vector3d(aPoint);
422-
v2.sub(cPoint);
423-
Vector3d v3 = new Vector3d(aPoint);
424-
v3.sub(dPoint);
425-
Vector3d v = new Vector3d(bPoint);
426-
v.add(cPoint);
427-
v.add(dPoint);
419+
Vector3d v1 = new Vector3d(focus);
420+
v1.sub(aNbor);
421+
Vector3d v2 = new Vector3d(focus);
422+
v2.sub(bNbor);
423+
Vector3d v3 = new Vector3d(focus);
424+
v3.sub(cNbor);
425+
Vector3d v = new Vector3d(v1);
426+
v.add(v2);
427+
v.add(v3);
428428
if (v.length() < 0.00001) {
429429
return null;
430430
}
431431
v.normalize();
432432
v.scale(length);
433-
Point3d point = new Point3d(aPoint);
433+
Point3d point = new Point3d(focus);
434434
point.add(v);
435435
return point;
436436
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* =====================================
3+
* Copyright (c) 2020 NextMove Software
4+
* =====================================
5+
*/
6+
7+
package org.openscience.cdk.geometry;
8+
9+
import org.hamcrest.number.IsCloseTo;
10+
import org.junit.Test;
11+
import org.openscience.cdk.exception.CDKException;
12+
import org.openscience.cdk.interfaces.IAtomContainer;
13+
import org.openscience.cdk.io.MDLV2000Reader;
14+
import org.openscience.cdk.silent.SilentChemObjectBuilder;
15+
16+
import javax.vecmath.Point3d;
17+
import java.io.IOException;
18+
import java.io.StringReader;
19+
20+
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.junit.Assert.assertNotNull;
22+
23+
public class AtomToolsTest {
24+
25+
@Test
26+
public void calculate3DCoordinates3() {
27+
String molfile = "\n" +
28+
" Mrv1810 12152010123D \n" +
29+
"\n" +
30+
" 4 3 0 0 0 0 999 V2000\n" +
31+
" 2.0575 1.4744 -0.0102 O 0 0 0 0 0 0 0 0 0 0 0 0\n" +
32+
" 1.5159 0.0200 0.0346 C 0 0 1 0 0 0 0 0 0 0 0 0\n" +
33+
" 2.0575 -0.7460 1.2717 N 0 0 0 0 0 0 0 0 0 0 0 0\n" +
34+
" -0.0359 -0.0059 -0.0102 C 0 0 0 0 0 0 0 0 0 0 0 0\n" +
35+
" 1 2 1 0 0 0 0\n" +
36+
" 2 3 1 0 0 0 0\n" +
37+
" 2 4 1 0 0 0 0\n" +
38+
"M END\n";
39+
try (MDLV2000Reader mdlr = new MDLV2000Reader(new StringReader(molfile))) {
40+
IAtomContainer mol = mdlr.read(SilentChemObjectBuilder.getInstance().newAtomContainer());
41+
Point3d newP = AtomTools.calculate3DCoordinates3(
42+
mol.getAtom(1).getPoint3d(),
43+
mol.getAtom(0).getPoint3d(),
44+
mol.getAtom(2).getPoint3d(),
45+
mol.getAtom(3).getPoint3d(), 1.5);
46+
assertNotNull(newP);
47+
assertThat(newP.x, IsCloseTo.closeTo(2.0160, 0.001));
48+
assertThat(newP.y, IsCloseTo.closeTo(-0.6871, 0.001));
49+
assertThat(newP.z, IsCloseTo.closeTo(-1.1901, 0.001));
50+
} catch (IOException | CDKException e) {
51+
e.printStackTrace();
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)