Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New ModelBuilder3D package test

Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
commit 07dbddb3f608b4fdb7c06cd158825137bbeb812e 1 parent a21ccc2
Daniel Szisz authored April 06, 2012 rajarshi committed April 18, 2012
213  src/test/org/openscience/cdk/modeling/builder3d/ForceFieldConfiguratorTest.java
... ...
@@ -0,0 +1,213 @@
  1
+package org.openscience.cdk.modeling.builder3d;
  2
+
  3
+
  4
+import static junit.framework.Assert.*;
  5
+
  6
+import java.util.List;
  7
+import java.util.regex.Matcher;
  8
+import java.util.regex.Pattern;
  9
+
  10
+import org.junit.Test;
  11
+import org.openscience.cdk.CDKConstants;
  12
+import org.openscience.cdk.DefaultChemObjectBuilder;
  13
+import org.openscience.cdk.exception.CDKException;
  14
+import org.openscience.cdk.interfaces.IAtom;
  15
+import org.openscience.cdk.interfaces.IAtomContainer;
  16
+import org.openscience.cdk.interfaces.IAtomType;
  17
+import org.openscience.cdk.interfaces.IChemObjectBuilder;
  18
+import org.openscience.cdk.interfaces.IRingSet;
  19
+import org.openscience.cdk.smiles.SmilesParser;
  20
+import org.openscience.cdk.tools.HOSECodeGenerator;
  21
+
  22
+/**
  23
+ * @author Daniel Szisz
  24
+ * @version 01/04/2012
  25
+ */
  26
+public class ForceFieldConfiguratorTest  {
  27
+
  28
+	ForceFieldConfigurator forceFieldConfigurator = new ForceFieldConfigurator();
  29
+	
  30
+	
  31
+	/*
  32
+	 * bug : ArrayIndexOutOfBoundsException because of wrong for loop
  33
+	 */
  34
+	@Test
  35
+	public void testCheckForceFieldType_String() {
  36
+		assertEquals(2, forceFieldConfigurator.getFfTypes().length);
  37
+		String validForceFieldType = "mm2";
  38
+		String invalidForceFieldType = "mmff2001";
  39
+		assertTrue(forceFieldConfigurator.checkForceFieldType(validForceFieldType));
  40
+		assertFalse(forceFieldConfigurator.checkForceFieldType(invalidForceFieldType));
  41
+		
  42
+	}
  43
+	
  44
+	@Test
  45
+	public void testSetForceFieldConfigurator_String() {
  46
+		String forceFieldName = "mmff94";
  47
+		try {
  48
+		forceFieldConfigurator.setForceFieldConfigurator(forceFieldName);
  49
+		List<IAtomType> mmff94AtomTypes = forceFieldConfigurator.getAtomTypes();
  50
+		assertNotNull(mmff94AtomTypes);
  51
+		IAtomType atomtype0 = mmff94AtomTypes.get(0);
  52
+		assertEquals("C", atomtype0.getAtomTypeName());
  53
+		IAtomType atomtype1 = mmff94AtomTypes.get(1);
  54
+		assertEquals("Csp2", atomtype1.getAtomTypeName());
  55
+		
  56
+		forceFieldName = "mm2";
  57
+		forceFieldConfigurator.setForceFieldConfigurator(forceFieldName);
  58
+		List<IAtomType> mm2AtomTypes = forceFieldConfigurator.getAtomTypes();
  59
+		assertNotNull(mm2AtomTypes);
  60
+		IAtomType atomtype2 = mm2AtomTypes.get(2);
  61
+		assertEquals("C=", atomtype2.getAtomTypeName());
  62
+		IAtomType atomtype3 = mm2AtomTypes.get(3);
  63
+		assertEquals("Csp", atomtype3.getAtomTypeName());
  64
+		
  65
+		} catch(CDKException cdkexp) {
  66
+			cdkexp.printStackTrace();
  67
+		}
  68
+	}
  69
+	
  70
+	@Test
  71
+	public void testSetMM2Parameters() {
  72
+		try {
  73
+		//FIXME bug : Problem within readParameterSets due 
  74
+			//to:java.lang.NullPointerException	
  75
+		forceFieldConfigurator.setMM2Parameters();
  76
+		assertNotNull(forceFieldConfigurator.getParameterSet());
  77
+		List<IAtomType> atomtypeList = forceFieldConfigurator.getAtomTypes();
  78
+		IAtomType atomtype1 = atomtypeList.get(1);
  79
+		assertEquals("Csp2", atomtype1.getAtomTypeName());
  80
+		assertEquals(6, (int) atomtype1.getAtomicNumber());
  81
+		assertEquals(12, (int) atomtype1.getMassNumber());
  82
+		
  83
+		} catch(CDKException cdkexp) {
  84
+			cdkexp.printStackTrace();
  85
+		}
  86
+	}
  87
+	
  88
+	@Test
  89
+	public void testSetMMFF94Parameters() {
  90
+		try {
  91
+		forceFieldConfigurator.setMMFF94Parameters();
  92
+		assertNotNull(forceFieldConfigurator.getParameterSet());
  93
+		List<IAtomType> atomtypeList = forceFieldConfigurator.getAtomTypes();
  94
+		IAtomType atomtype4 = atomtypeList.get(4);
  95
+		assertEquals("CO2M", atomtype4.getAtomTypeName());
  96
+		assertEquals(6, (int) atomtype4.getAtomicNumber());
  97
+		assertEquals(4, (int) atomtype4.getFormalNeighbourCount());
  98
+		assertEquals(12, (int) atomtype4.getMassNumber());
  99
+		
  100
+		} catch(Exception e) {
  101
+			e.printStackTrace();
  102
+		}
  103
+	}
  104
+	
  105
+	@Test
  106
+	public void testRemoveAromaticityFlagsFromHoseCode_String() {
  107
+		String hosecode1 = "***HO*SE*CODE***";
  108
+		String cleanHoseCode = forceFieldConfigurator.removeAromaticityFlagsFromHoseCode(hosecode1);
  109
+		assertEquals("HOSECODE",cleanHoseCode);
  110
+		String hosecode2 = "HOSECODE";
  111
+		cleanHoseCode = forceFieldConfigurator.removeAromaticityFlagsFromHoseCode(hosecode2);
  112
+		assertEquals("HOSECODE", cleanHoseCode);
  113
+		
  114
+	}
  115
+	
  116
+	@Test
  117
+	public void testConfigureMM2BasedAtom_IAtom_String_boolean() {
  118
+			
  119
+	}
  120
+	
  121
+	/*
  122
+	 * bug : mmff94 atom types N and N3OX are given 
  123
+	 */
  124
+	@Test
  125
+	public void testConfigureMMFF94BasedAtom_IAtom_String_boolean_hydroxyurea() throws CDKException {
  126
+		String husmi = "NC(=O)NO";
  127
+		IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
  128
+		SmilesParser parser = new SmilesParser(builder);
  129
+		IAtomContainer hu = parser.parseSmiles(husmi);
  130
+		ForceFieldConfigurator ffc = new ForceFieldConfigurator();
  131
+		ffc.setForceFieldConfigurator("mmff94");
  132
+		IAtom N1= hu.getAtom(0);
  133
+		IAtom N2 = hu.getAtom(3);
  134
+		ffc.configureAtom(N1, 
  135
+				new HOSECodeGenerator().getHOSECode(hu, N1, 3),
  136
+				false);
  137
+		ffc.configureAtom(N2, 
  138
+				new HOSECodeGenerator().getHOSECode(hu, N2, 3),
  139
+				false);
  140
+		assertEquals("NC=O", N1.getAtomTypeName());
  141
+		assertEquals("N2OX", N2.getAtomTypeName());
  142
+			
  143
+	}
  144
+	
  145
+	@Test
  146
+	public void testConfigureMMFF94BasedAtom_IAtom_String_boolean_propanamide() throws CDKException {
  147
+		String pasmi = "NC(=O)CC";
  148
+		IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
  149
+		SmilesParser parser = new SmilesParser(builder);
  150
+		IAtomContainer pa = parser.parseSmiles(pasmi);
  151
+		ForceFieldConfigurator ffc = new ForceFieldConfigurator();
  152
+		ffc.setForceFieldConfigurator("mmff94");
  153
+		IAtom amideN = pa.getAtom(0);
  154
+		ffc.configureMMFF94BasedAtom(amideN, 
  155
+				new HOSECodeGenerator().getHOSECode(pa, amideN, 3), 
  156
+				false);
  157
+	    assertEquals("NC=O", amideN.getAtomTypeName());	
  158
+		
  159
+	}
  160
+	
  161
+	/*
  162
+	 * bug : mmff94 atomtype N instead of NC=O
  163
+	 */
  164
+	@Test
  165
+	public void testConfigureMMFF94BasedAtom_IAtom_String_boolean_urea() throws CDKException {
  166
+		String usmi = "NC(N)=O";
  167
+		IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
  168
+		SmilesParser parser = new SmilesParser(builder);
  169
+		IAtomContainer urea = parser.parseSmiles(usmi);
  170
+		ForceFieldConfigurator ffc = new ForceFieldConfigurator();
  171
+		ffc.setForceFieldConfigurator("mmff94");
  172
+		IAtom amideN = urea.getAtom(0);
  173
+		ffc.configureMMFF94BasedAtom(amideN, 
  174
+				new HOSECodeGenerator().getHOSECode(urea, amideN, 3), 
  175
+				false);
  176
+//		System.err.println(amideN.getAtomTypeName());
  177
+		assertEquals("NC=O", amideN.getAtomTypeName());
  178
+		
  179
+	}
  180
+		
  181
+	/*
  182
+	 * bug : bad atom types
  183
+	 */
  184
+	@Test 
  185
+	public void testAssignAtomTyps_test4_hydroxyurea() throws CDKException {
  186
+		String smiles = "C(=O)(NO)N";
  187
+	    String[] originalAtomTypes = {"C.sp2","O.sp2","N.amide","O.sp3","N.amide"}; 
  188
+        String[] expectedAtomTypes = {"C=","O=","NC=O","O","N2OX"};
  189
+    	IAtomContainer molecule = null;
  190
+    	String[] ffAtomTypes=null;
  191
+    	
  192
+        IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
  193
+		SmilesParser smilesParser = new SmilesParser(builder);
  194
+		molecule = smilesParser.parseSmiles(smiles);
  195
+		ffAtomTypes = new String[molecule.getAtomCount()];
  196
+		
  197
+		for(int i=0; i<molecule.getAtomCount(); i++) {
  198
+			assertEquals(originalAtomTypes[i],molecule.getAtom(i).getAtomTypeName());	
  199
+		     }
  200
+		forceFieldConfigurator.setForceFieldConfigurator("mmff94");	
  201
+		IRingSet moleculeRingSet = forceFieldConfigurator.assignAtomTyps(molecule);
  202
+		//no rings
  203
+		assertEquals(0, moleculeRingSet.getAtomContainerCount());
  204
+		for(int i=0; i< molecule.getAtomCount(); i++) {
  205
+			IAtom mmff94atom = molecule.getAtom(i);
  206
+			assertTrue(mmff94atom.getFlag(CDKConstants.ISALIPHATIC));
  207
+			ffAtomTypes[i] = mmff94atom.getAtomTypeName();
  208
+		 }
  209
+		 assertEquals(expectedAtomTypes, ffAtomTypes);
  210
+		
  211
+	}
  212
+
  213
+}

0 notes on commit 07dbddb

Please sign in to comment.
Something went wrong with that request. Please try again.