Commits

Anonymous committed e00baf1 Draft

gradually restoring tests

  • Participants
  • Parent commits 1ac9f9a

Comments (0)

Files changed (8)

src/main/java/org/xmlcml/declaratron/core/visitors/EditorVisitable.java

 			addChild();
 		} else if (COPY_CHILD.equals(method)) {
 			this.addAttribute(new Attribute("USED", "TRUE"));
+			getFrom(true);
 			copyChild();
 		} else if (DELETE_NODES.equals(method)) {
 			deleteNodes();

src/test/java/org/xmlcml/declaratron/core/Fixtures.java

 	public static final String CORE       = "org/xmlcml/declaratron/core/";
 	public static final String VISITORS   = CORE+"visitors/";
 	public static final String COMPOUND   = VISITORS+"compound/";
+	public static final String DEVELOP    = VISITORS+"develop/";
+	public static final String EDITOR     = VISITORS+"editor/";
 	public static final String HREF       = VISITORS+"href/";
 	public static final String KEY_VALUE  = VISITORS+"keyValue/";
-	public static final String EDITOR     = VISITORS+"editor/";
 
 }

src/test/java/org/xmlcml/declaratron/core/visitors/develop/PaperTest.java

+package org.xmlcml.declaratron.core.visitors.develop;
+
+import nu.xom.Element;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.xmlcml.cml.testutil.JumboTestUtils;
+import org.xmlcml.declaratron.core.CMLClassVisitor;
+import org.xmlcml.declaratron.core.Fixtures;
+import org.xmlcml.declaratron.core.NodeUtils;
+import org.xmlcml.declaratron.core.visitors.HREFVisitor;
+import org.xmlcml.declaratron.core.visitors.KeyValueVisitor;
+import org.xmlcml.declaratron.core.visitors.VisitorListVisitor;
+
+/** test examples in our paper
+ * 
+ * @author pm286
+ *
+ */
+public class PaperTest {
+
+	@Test
+	@Ignore
+	public void testPaperExample
+	() {
+		
+		Element combinedDoc = NodeUtils.parseResource(Fixtures.DEVELOP+"paper.xml");
+		VisitorListVisitor combinedVisitor = new VisitorListVisitor();
+		HREFVisitor hVisitor = new HREFVisitor();
+		hVisitor.setUseTreeVisit(true);
+		combinedVisitor.add(hVisitor);
+		CMLClassVisitor cVisitor = new CMLClassVisitor();
+		combinedVisitor.add(cVisitor);
+		KeyValueVisitor kVisitor = new KeyValueVisitor(combinedDoc);
+		kVisitor.setUseTreeVisit(true);
+		combinedVisitor.add(kVisitor);
+		Element element0 = combinedVisitor.visitElement(combinedDoc);
+		
+		Assert.assertEquals("visited", 120, combinedVisitor.getVisitedNodes().size());
+		Assert.assertEquals("changed", 9, combinedVisitor.getChangedNodes().size());
+		Assert.assertEquals("failed", 1, combinedVisitor.getFailedNodes().size());
+		JumboTestUtils.assertEqualsIncludingFloat(
+				"test compare",NodeUtils.parseResource(Fixtures.DEVELOP+"paperOut.xml"), combinedDoc, true, 0.001);
+		
+	}
+
+
+}

src/test/resources/org/xmlcml/declaratron/core/visitors/compound/compound.xml

 	<queryNSList>
 		<queryNS prefix="semc" uri="http://www.xml-cml.org/semanticcomputation" />
 		<queryNS prefix="semf" uri="http://www.xml-cml.org/semanticforcefields" />
-		<queryNS prefix="cml" uri="http://www.xml-cml.org/schema" />
+		<queryN"src/test/resources/org/xmlcml/declaratron/core/visitors/develop/paper.xml"S prefix="cml" uri="http://www.xml-cml.org/schema" />
 		<queryNS prefix="m" uri="http://www.w3.org/1998/Math/MathML" />
 		<queryNS prefix="cmlx" uri="http://www.xml-cml.org/schema/cmlx" />
 	</queryNSList>

src/test/resources/org/xmlcml/declaratron/core/visitors/develop/paper.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!-- The \lstinline{<computation>} node is a container for the entire computation. We also define XML namespaces which can be used throughout the file.
+\begin{lstlisting}[basicstyle=\footnotesize\ttfamily, name="acetic"]-->
+<computation xmlns="http://www.xml-cml.org/semanticcomputation"
+    xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:cml="http://www.xml-cml.org/schema"
+    xmlns:amber='http://www.xml-cml.org/dict/amber:gaffType'>
+    
+
+<!-- Now, we define the visitors to be used. These are objects which will visit each node of the tree in turn, and carry out some action. In this case, we have three: one to resolve includes (HREFs) by pulling in data from other files (or URIs), and two which \emph{decorate} the tree by replacing standard Xom nodes with domain specific objects:
+ -->
+     <visitor class="org.xmlcml.semantic.visitors.HREFVisitor"/>
+    <visitor class="org.xmlcml.cml.chemistry.SemanticChemistryClasses"/>
+    <visitor class="org.xmlcml.cml.chemistry.CMLClassDecorator"/>
+
+<!-- 
+In this case, \lstinline{CMLClassDecorator} uses the existing CML object factory to introduce CML classes into the tree, and \lstinline{SemanticChemistryClasses} introduces a collection of generally useful operations for semantic computation: assertions, unit conversions, input/output, as well as some chmistry specific operations which use the Jumbo libraries to perform operations on atoms and molecules.
+-->
+
+<!-- It is necessary to set up XML namespaces for carrying out XPath queries. \todo{maybe we don't need to say this...}
+-->
+    <!-- setup XML namespaces for use in XPath queries -->
+    <queryNS prefix="semc" uri="http://www.xml-cml.org/semanticcomputation"/>
+    <queryNS prefix="semf" uri="http://www.xml-cml.org/semanticforcefields"/>
+    <queryNS prefix="cml" uri="http://www.xml-cml.org/schema"/>
+    <queryNS prefix="m" uri="http://www.w3.org/1998/Math/MathML"/>
+    <queryNS prefix="amber" uri="http://www.xml-cml.org/dict/amber:gaffType" />
+    <queryNS prefix="cmlx" uri="http://www.xml-cml.org/schema/cmlx" />
+
+<!-- 
+Throughout the file, key/value pairs wee used to reduce repetition. Next, we load in the molecule which we want to work with. TAlthough tis could be specified inline, bsing an external file through a HREF allows for re-use of comm files.:
+-->
+    <!-- setup the molecule and forcefield -->
+    <keyValue name="forcefield" value="src/test/resources/org/xmlcml/cml/forcefield"/>
+    <keyValue name="molpath" value="//cml:molecule[@id='molecule']"/>
+    <keyValue name="bondpath" value="${molpath}/cml:bondArray/cml:bond"/>
+    <keyValue name="atompath" value="${molpath}/cml:atomArray/cml:atom"/>
+    <cml:molecule id="molecule" href="${forcefield}/aceticStart.cml" />
+<!--     
+The \lstinline{<cml:molecule>} element will end up with the set of atoms and bonds specified in the given file. In order to ensure that all atoms have identifying information which we can use with the AMBER parm94 dictionary, an \lstinline{<assert>} element checks that there are 0 atoms without a valid id:
+-->
+    <!--  all atoms in the document must have atomTypes -->
+    <assert count="0" xpath="${atompath}[not(cml:atomType[@dictRef='amber:parm94Type'])]"/>
+
+<!-- 
+Given a molecule with correct atom ids, we can load in the parameters we need to use in forcefield equations. This is a two step process - first load the database, and second attach the correct data to each atom
+-->
+    <!-- list is default type for general data -->
+    <cml:list id="parm94Test" href="src/main/resources/org/xmlcml/cml/forcefield/amber/parm94test.xml"/>
+    <!--  add hash based on atomType children -->
+    <atomTypeTool method="addAtomTypesId" using="./cml:atomType"
+        xpath="//cml:list[@id='parm94Test']/cml:list/cml:list[count(cml:atomType)>0]" />
+        
+    <unitsVisitor xpath="//cml:list[@id='parm94Test']//cml:scalar[@dictRef='ff:angeq' or @dictRef='ff:phase']" method="degrees2Radians"/>
+
+    <writer xpath="//cml:list[@id='parm94Test']" file="output/parm94testNew.xml" /> 
+
+<!-- === create/ensure bonds, angles, torsions, nonbonded and then hash atom types === -->
+    
+    <moleculeTool method="getOrCreateBonds" xpath="${molpath}" setId="createdBonds"/>
+   <!-- similar operations with moleculeTool removed for brevity -->
+
+    <writer xpath="${molpath}" file="output/testAtomTypes0.xml" /> 
+    
+<!-- =========== copy parameters to bonds and tidy ============== -->
+    
+    <xpathVisitor method="addChild" xpath="${bondpath}" args="org.xmlcml.cml.element.CMLProperty"/>
+    <xpathVisitor method="copyChild"
+        xpath="//cml:molecule[@id='molecule']/cml:bondArray" 
+            from="//cml:list[@id='parm94Test']/cml:list[@title='bonds']/semf:functionalForm" />
+    <xpathVisitor method="copyChild"
+        xpath="//cml:molecule[@id='molecule']/cml:bondArray/cml:bond/cml:property" key="../@cmlx:atomTypesId"
+            from="//cml:list[@id='parm94Test']/cml:list[@title='bonds']" using="./cml:list[@cmlx:atomTypesId='$key']" />
+    <xpathVisitor method="deleteNodes"
+         xpath="//cml:molecule[@id='molecule']/cml:bondArray/cml:bond/cml:property/cml:list/cml:atomType" />
+
+<!-- =========== do the same for angles, torsions and non-bondeds (omitted for brevity) ============== -->
+
+    <!-- write out entire document before computation as a record -->
+    <writer xpath="/*" file="output/all.xml" /> 
+    <!-- calculate the energy of the forcefield in the initial configuration -->
+    
+
+    <energyVisitor xpath="//cml:molecule" xpath1=".//semf:functionalForm" method="singlePoint" />
+    <!-- now optimise the position of the atoms using a direct search optimisation -->
+    <energyVisitor xpath="//cml:molecule" xpath1=".//semf:functionalForm" method="optimise" />
+    <!-- write the complete document out, including results -->
+    <writer xpath="/*" file="output/output.cml" /> 
+</computation>

src/test/resources/org/xmlcml/declaratron/core/visitors/develop/paperOut.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<computation/>

src/test/resources/org/xmlcml/declaratron/core/visitors/editor/child0.xml

   </bar>
   <bar id="b"/>
   <bar id="c" value="b"/>
-  <editor method="copyChild" xpath="//plugh"/>
+  <editor method="copyChild" xpath="//plugh" from="//bar[@id='c']"/>
 </foo>

src/test/resources/org/xmlcml/declaratron/core/visitors/editor/child0out.xml

 <foo>
-<bar id="a" />
-<bar />
-<bar id="c" />
-<editor method="deleteNodes" xpath="//@value" />
-<editor method="deleteNodes" xpath="//@*[.='b']" />
+<bar id="a">
+<plugh id="p">
+<bar id="c" value="b" />
+</plugh>
+</bar>
+<bar id="b" />
+<bar id="c" value="b" />
+<editor method="copyChild" xpath="//plugh" from="//bar[@id='c']" USED="TRUE" />
 </foo>