-
Notifications
You must be signed in to change notification settings - Fork 154
/
AtomPlacer3DTest.java
158 lines (141 loc) · 5.91 KB
/
AtomPlacer3DTest.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* $Revision: 12144 $ $Author: egonw $ $Date: 2008-09-02 21:53:30 +0100 (Tue, 02 Sep 2008) $
*
* Copyright (C) 2005-2007 Christian Hoppe <chhoppe@users.sf.net>
*
* Contact: cdk-devel@list.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.modeling.builder3d;
import java.io.InputStream;
import java.util.List;
import javax.vecmath.Point3d;
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemObject;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.nonotify.NNMolecule;
import org.openscience.cdk.templates.MoleculeFactory;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
/**
* Tests for AtomPlacer3D
*
* @cdk.module test-builder3d
* @cdk.githash
*/
public class AtomPlacer3DTest extends CDKTestCase{
boolean standAlone = false;
/**
* Sets the standAlone attribute
*
*@param standAlone The new standAlone value
*/
public void setStandAlone(boolean standAlone)
{
this.standAlone = standAlone;
}
@Test
public void testAllHeavyAtomsPlaced_IAtomContainer(){
IAtomContainer ac=MoleculeFactory.makeAlphaPinene();
Assert.assertFalse(new AtomPlacer3D().allHeavyAtomsPlaced(ac));
for(IAtom atom : ac.atoms()){
atom.setFlag(CDKConstants.ISPLACED,true);
}
Assert.assertTrue(new AtomPlacer3D().allHeavyAtomsPlaced(ac));
}
@Test
public void testFindHeavyAtomsInChain_IAtomContainer_IAtomContainer() throws Exception{
String filename = "data/mdl/allmol232.mol";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
// TODO: shk3-cleanuptests: best to use the STRICT IO mode here
MDLV2000Reader reader = new MDLV2000Reader(ins);
ChemFile chemFile = (ChemFile)reader.read((ChemObject)new ChemFile());
// TODO: shk3-cleanuptests: please make it a types list
List containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
IMolecule ac = new NNMolecule((IAtomContainer)containersList.get(0));
addExplicitHydrogens(ac);
IAtomContainer chain=ac.getBuilder().newInstance(IAtomContainer.class);
for(int i=16;i<25;i++){
chain.addAtom(ac.getAtom(i));
}
chain.addAtom(ac.getAtom(29));
chain.addAtom(ac.getAtom(30));
int[] result=new AtomPlacer3D().findHeavyAtomsInChain(ac,chain);
Assert.assertEquals(16,result[0]);
Assert.assertEquals(11,result[1]);
}
@Test
public void testNumberOfUnplacedHeavyAtoms_IAtomContainer(){
IMolecule ac = MoleculeFactory.makeAlphaPinene();
int count=new AtomPlacer3D().numberOfUnplacedHeavyAtoms(ac);
Assert.assertEquals(10,count);
}
@Test
public void testGetPlacedHeavyAtoms_IAtomContainer_IAtom(){
IMolecule ac = MoleculeFactory.makeAlphaPinene();
IAtomContainer acplaced = new AtomPlacer3D().getPlacedHeavyAtoms(ac, ac.getAtom(0));
Assert.assertEquals(0,acplaced.getAtomCount());
ac.getAtom(1).setFlag(CDKConstants.ISPLACED, true);
acplaced = new AtomPlacer3D().getPlacedHeavyAtoms(ac, ac.getAtom(0));
Assert.assertEquals(1,acplaced.getAtomCount());
}
@Test
public void testGetPlacedHeavyAtom_IAtomContainer_IAtom_IAtom(){
IMolecule ac = MoleculeFactory.makeAlphaPinene();
IAtom acplaced = new AtomPlacer3D().getPlacedHeavyAtom(ac, ac.getAtom(0), ac.getAtom(1));
Assert.assertNull(acplaced);
ac.getAtom(1).setFlag(CDKConstants.ISPLACED, true);
acplaced = new AtomPlacer3D().getPlacedHeavyAtom(ac, ac.getAtom(0),ac.getAtom(2));
Assert.assertEquals(ac.getAtom(1),acplaced);
acplaced = new AtomPlacer3D().getPlacedHeavyAtom(ac, ac.getAtom(0),ac.getAtom(1));
Assert.assertNull(acplaced);
}
@Test
public void testGetPlacedHeavyAtom_IAtomContainer_IAtom(){
IMolecule ac = MoleculeFactory.makeAlphaPinene();
IAtom acplaced = new AtomPlacer3D().getPlacedHeavyAtom(ac, ac.getAtom(0));
Assert.assertNull(acplaced);
ac.getAtom(1).setFlag(CDKConstants.ISPLACED, true);
acplaced = new AtomPlacer3D().getPlacedHeavyAtom(ac, ac.getAtom(0));
Assert.assertEquals(ac.getAtom(1),acplaced);
}
@Test
public void testGeometricCenterAllPlacedAtoms_IAtomContainer() throws Exception {
IMolecule ac = MoleculeFactory.makeAlphaPinene();
for(int i=0;i<ac.getAtomCount();i++){
ac.getAtom(i).setFlag(CDKConstants.ISPLACED, true);
}
ac.getAtom(0).setPoint3d(new Point3d(1.39,2.04,0));
ac.getAtom(0).setPoint3d(new Point3d(2.02,2.28,-1.12));
ac.getAtom(0).setPoint3d(new Point3d(3.44,2.80,-1.09));
ac.getAtom(0).setPoint3d(new Point3d(3.91,2.97,0.35));
ac.getAtom(0).setPoint3d(new Point3d(3.56,1.71,1.16));
ac.getAtom(0).setPoint3d(new Point3d(2.14,2.31,1.29));
ac.getAtom(0).setPoint3d(new Point3d(0,1.53,0));
ac.getAtom(0).setPoint3d(new Point3d(2.83,3.69,1.17));
ac.getAtom(0).setPoint3d(new Point3d(3.32,4.27,2.49));
ac.getAtom(0).setPoint3d(new Point3d(2.02,4.68,0.35));
Point3d center=new AtomPlacer3D().geometricCenterAllPlacedAtoms(ac);
Assert.assertEquals(2.02, center.x,0.01);
Assert.assertEquals(4.68, center.y,0.01);
Assert.assertEquals(0.35, center.z,0.01);
}
}