Commits

Anonymous committed d6d0c51

computed eqn 3.5 etc

Comments (0)

Files changed (5)

src/test/java/org/xmlcml/cml/forcefield/kk/ComputationTest.java

 package org.xmlcml.cml.forcefield.kk;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
 import nu.xom.Element;
 
 import org.junit.Ignore;
 import org.xmlcml.cml.chemistry.ArrayToolVisitable;
 import org.xmlcml.cml.chemistry.TableToolVisitable;
 import org.xmlcml.cml.testutil.JumboTestUtils;
+import org.xmlcml.mathml.Context;
+import org.xmlcml.mathml.MathMLElement;
+import org.xmlcml.mathml.MathMLParser;
 import org.xmlcml.semantic.NodeUtils;
 import org.xmlcml.semantic.visitors.ExecutableVisitor;
 
+import scala.actors.threadpool.Arrays;
+
 public class ComputationTest {
 
 	/**
 	 * computes details of Kihara+Kobe J. Phys. Soc Japan, 7, 1952, 348-354
 	 * 
 	 */
+	private static final String TEST_TOP = "src/test/resources/";
 	private static final String KK_DIR = "org/xmlcml/cml/forcefield/kk/";
 	private static final String COMPUTATION = "Comp";
+	private static List<Double> N_LIST = (List<Double>)Arrays.asList(
+			new Double[] {
+					Double.NaN,
+					12., 6., 24., 12., 24.,
+					8., 48., 6., 36., 24.,
+					24., 24., 72., 48., 12.,
+					48., 30., 72., 24., 48.,
+					24., 48., 8., 84., 24.,
+					96., 48., 24., 96., 6.,
+					96., 48., 48., 36., 120.,
+					24., 48., 24., 48., 48.,
+					120., 24., 120., 96., 24., 
+					108., 30., 48., 72., 72.,
+					32., 144., 96., 72., 72.,
+					48., 120., 144., 12., 72.,
+				});
+
+	static List<Double> A_LIST
+	= (List<Double>)Arrays.asList(
+			new Double[] {Double.NaN,
+					1., 2., 3., 4., 5.,
+					6., 7., 8., 9., 10.,
+					11., 12., 13., 15., 16.,
+					17., 18., 19., 20., 21.,
+					22., 23., 24., 25., 26.,
+					27., 28., 29., 31., 32.,
+					33., 34., 35., 36., 37.,
+					38., 39., 40., 41., 42.,
+					43., 44., 45., 47., 48.,
+					49., 50., 51., 52., 53.,
+					54., 55., 57., 58., 59., 
+					60., 61., 63., 64., 65.
+			});
 
 	/**
 	 * computes LJ curves with different values of parameters
 		String PROBLEM = "lennardJones"+COMPUTATION;
 
 		Element element = NodeUtils.parseResource(KK_DIR + PROBLEM+ ".xml");
-		Element arrayToolElement = (Element) element.query(
-				"//*[local-name()='arrayTool']").get(0);
+		Element arrayToolElement = (Element) element.query("//*[local-name()='arrayTool']").get(0);
 		ArrayToolVisitable visitable = new ArrayToolVisitable(arrayToolElement);
 		ExecutableVisitor visitor = new ExecutableVisitor();
 		Element newElement = visitor.visitElement(visitable);
 	}
 
 	@Test
+	public void testAtheta() {
+		MathMLParser b = new MathMLParser();
+		MathMLElement<?> expr = b.buildDoubleExpressionFromFile(
+				TEST_TOP+KK_DIR+"atheta.xml");
+		Context context = new Context();
+		context.setVar("n", N_LIST);
+		context.setVar("pi", Math.PI);
+		double[] expected = {
+				14.45392, 13.35939, 12.80194, 12.49255, 12.31125, 12.13188, 12.05899, 12.02736, 12.01300};
+		double[] ss = {6., 7., 8., 9.,10., 12., 14., 16., 18.};
+		for (int theta = 1; theta <N_LIST.size(); theta++) {
+			context.setVar("theta", (double) theta);
+			Object f = expr.eval(context );
+			System.out.println(f);
+//			Assert.assertEquals("ss: "+ss[i], expected[i], (double) (Double) f, 0.00001);
+		}
+	}
+
+	@Test
+	public void testTerm2() {
+		MathMLParser b = new MathMLParser();
+		MathMLElement<?> expr = b.buildDoubleExpressionFromFile(
+				TEST_TOP+KK_DIR+"term2.xml");
+		Context context = new Context();
+		context.setVar("n", N_LIST);
+		context.setVar("pi", Math.PI);
+		context.setVar("s", 6);
+		double[] expected = {
+				14.45392, 13.35939, 12.80194, 12.49255, 12.31125, 12.13188, 12.05899, 12.02736, 12.01300};
+		double[] ss = {6., 7., 8., 9.,10., 12., 14., 16., 18.};
+		for (int theta = 1; theta <N_LIST.size(); theta++) {
+			context.setVar("theta", (double) theta);
+			Object f = expr.eval(context );
+			System.out.println(f);
+//			Assert.assertEquals("ss: "+ss[i], expected[i], (double) (Double) f, 0.00001);
+		}
+	}
+
+		@Test
+	public void testPotentialEnergySum0() {
+		
+		MathMLParser b = new MathMLParser();
+		MathMLElement<?> expr = b.buildDoubleExpressionFromFile(
+				TEST_TOP+KK_DIR+"potentialEnergySum.xml");
+		Context context = new Context();
+		
+		context.setVar("a", A_LIST);
+		context.setVar("n", N_LIST);
+		context.setVar("pi", Math.PI);
+		context.setVar("theta", 40.0);
+//		context.setVar("theta", 50.0);
+		double[] expected = {
+				14.45392, 13.35939, 12.80194, 12.49255, 12.31125, 12.13188, 12.05899, 12.02736, 12.01300};
+		double[] ss = {6., 7., 8., 9.,10., 12., 14., 16., 18.};
+		for (int i = 0;i <ss.length; i++) {
+			context.setVar("s", ss[i]);
+			Object f = expr.eval(context );
+			Assert.assertEquals("ss: "+ss[i], expected[i], (double) (Double) f, 0.00001);
+		}
+		
+
+	}
+
+
+	@Test
 	@Ignore // FIXME
-	public void testPotentialEnergy() {
+	public void testPotentialEnergyCubic() {
 
 		Element element = NodeUtils
 				.parseResource(KK_DIR+"table1Cubic.xml");

src/test/resources/org/xmlcml/cml/forcefield/kk/atheta.xml

+<math display='block'>
+	<apply id="denominator.powerbracket">
+		<power />
+		<apply id="largebracket">
+			<times />
+			<apply id="3overroot32pi">
+				<divide />
+				<cn>3</cn>
+				<apply>
+					<times />
+					<apply>
+						<root />
+						<cn>32</cn>
+					</apply>
+					<ci>pi</ci>
+				</apply>
+			</apply>
+			<apply id="summationbracket">
+				<plus />
+				<cn>1</cn>
+				<apply id="summation">
+					<sum />
+					<bvar>
+						<ci>i</ci>
+					</bvar>
+					<lowlimit>
+						<cn>1</cn>
+					</lowlimit>
+					<uplimit>
+						<ci>theta</ci>
+					</uplimit>
+					<apply>
+						<selector />
+						<ci type="vector">n</ci>
+						<ci>i</ci>
+					</apply>
+				</apply>
+			</apply>
+		</apply>
+		<apply>
+			<divide />
+			<cn>1</cn>
+			<cn>3</cn>
+		</apply>
+	</apply>
+</math>

src/test/resources/org/xmlcml/cml/forcefield/kk/potentialEnergySum.xml

 <math display='block'>
-  <apply>
-    <plus />
-    <apply>
-      <sum />
-      <bvar>
-        <ci>i</ci>
-      </bvar>
-      <lowlimit>
-        <cn>1</cn>
-      </lowlimit>
-      <uplimit>
-        <ci>n</ci>
-      </uplimit>
-      <apply>
-        <times />
-        <apply>
-          <selector />
-          <ci type="vector">b</ci>
-          <ci>i</ci>
-        </apply>
-        <apply>
-          <power />
-          <apply>
-            <selector />
-            <ci type="vector">a</ci>
-            <ci>i</ci>
-          </apply>
-          <apply>
-            <minus />
-            <apply>
-              <divide />
-              <ci>s</ci>
-              <cn>2</cn>
-            </apply>
-          </apply>
-        </apply>
-      </apply>
-    </apply>
-    
-    <apply>
-      <divide />
-      <apply>
-        <apply>
-          <times />
-          <ci>pi</ci>
-          <apply>
-            <root />
-            <cn>32</cn>
-          </apply>
-        </apply>
-      </apply>
-      <apply>
-        <times />
-        <apply>
-          <minus />
-          <ci>s</ci>
-          <cn>3</cn>
-        </apply>
-        <apply>
-        <!-- 
-          <power />
-          <apply>
-            <times />
-            <apply>
-              <apply>
-                <divide />
-                <cn>3</cn>
-                <apply>
-                  <times />
-                  <apply>
-                    <root />
-                    <cn>32</cn>
-                  </apply>
-                  <ci>pi</ci>
-                </apply>
-              </apply>
-              <apply>
-                <apply>
-                  <plus />
-                  <cn>1</cn>
-                  <apply>
-                    <sum />
-                    <bvar>
-                      <ci>i</ci>
-                    </bvar>
-                    <lowlimit>
-                      <cn>1</cn>
-                    </lowlimit>
-                    <uplimit>
-                      <ci>n</ci>
-                    </uplimit>
-                    <apply>
-                      <selector />
-                      <ci type="vector">b</ci>
-                      <ci>i</ci>
-                    </apply>
-                  </apply>
-                </apply>
-              </apply>
-            </apply>
-          </apply>
-          <apply>
-            <divide />
-            <apply>  
-              <minus />
-              <ci>s</ci>
-              <cn>3</cn>
-            </apply>
-            <cn>3</cn>
-          </apply>
-        -->
-          <root/>
-          <cn>10</cn>
-        </apply>
-      </apply>
-    </apply>
-    
-  </apply>
+	<apply>
+		<plus />
+		<apply id="term1">
+			<sum />
+			<bvar>
+				<ci>i</ci>
+			</bvar>
+			<lowlimit>
+				<cn>1</cn>
+			</lowlimit>
+			<uplimit>
+				<ci>theta</ci>
+			</uplimit>
+			<apply id="summand">
+				<times />
+				<apply id="nsubi">
+					<selector />
+					<ci type="vector">n</ci>
+					<ci>i</ci>
+				</apply>
+				<apply id="apower-s/2">
+					<power />
+					<apply id="asubi">
+						<selector />
+						<ci type="vector">a</ci>
+						<ci>i</ci>
+					</apply>
+					<apply is="minuss/2">
+						<minus />
+						<apply>
+							<divide />
+							<ci>s</ci>
+							<cn>2</cn>
+						</apply>
+					</apply>
+				</apply>
+			</apply>
+		</apply>
+		<apply id="term2">
+			<divide />
+			<apply id="term2.numerator">
+				<times />
+				<ci>pi</ci>
+				<apply>
+					<root />
+					<cn>32</cn>
+				</apply>
+			</apply>
+			<apply id="term2.denominator">
+				<times />
+				<apply id="term2.sminus3">
+					<minus />
+					<ci>s</ci>
+					<cn>3</cn>
+				</apply>
+				<apply>
+					<power />
+					<apply id="denominator.powerbracket">
+						<power />
+						<apply id="largebracket">
+							<times />
+							<apply id="3overroot32pi">
+								<divide />
+								<cn>3</cn>
+								<apply>
+									<times />
+									<apply>
+										<root />
+										<cn>32</cn>
+									</apply>
+									<ci>pi</ci>
+								</apply>
+							</apply>
+							<apply id="summationbracket">
+								<plus />
+								<cn>1</cn>
+								<apply id="summation">
+									<sum />
+									<bvar>
+										<ci>i</ci>
+									</bvar>
+									<lowlimit>
+										<cn>1</cn>
+									</lowlimit>
+									<uplimit>
+										<ci>theta</ci>
+									</uplimit>
+									<apply>
+										<selector />
+										<ci type="vector">n</ci>
+										<ci>i</ci>
+									</apply>
+								</apply>
+							</apply>
+						</apply>
+						<apply>
+							<divide />
+							<cn>1</cn>
+							<cn>3</cn>
+						</apply>
+					</apply>
+					<apply id="denominator.exponent">
+						<minus />
+						<ci>s</ci>
+						<cn>3</cn>
+					</apply>
+				</apply>
+			</apply>
+		</apply>
+	</apply>
 </math>

src/test/resources/org/xmlcml/cml/forcefield/kk/potentialEnergySum0.xml

+<math display='block'>
+	<apply>
+		<plus />
+		<apply id="term1">
+			<sum />
+			<bvar>
+				<ci>i</ci>
+			</bvar>
+			<lowlimit>
+				<cn>1</cn>
+			</lowlimit>
+			<uplimit>
+				<ci>theta</ci>
+			</uplimit>
+			<apply id="summand">
+				<times />
+				<apply id="nsubi">
+					<selector />
+					<ci type="vector">n</ci>
+					<ci>i</ci>
+				</apply>
+				<apply id="apower-s/2">
+					<power />
+					<apply id="asubi">
+						<selector />
+						<ci type="vector">a</ci>
+						<ci>i</ci>
+					</apply>
+					<apply is="minuss/2">
+						<minus />
+						<cn>0</cn>
+						<apply>
+							<divide />
+							<ci>s</ci>
+							<cn>2</cn>
+						</apply>
+					</apply>
+				</apply>
+			</apply>
+		</apply>
+		<apply id="term2" >
+			<divide/>
+			<apply id="term2.numerator">
+				<times />
+				<ci>pi</ci>
+				<apply>
+					<root />
+					<cn>32</cn>
+				</apply>
+			</apply>
+			<apply id="term2.denominator">
+				<times />
+				<apply id="term2.sminus3">
+					<minus />
+					<ci>s</ci>
+					<cn>3</cn>
+				</apply>
+				<apply id="denominator.powerbracket">
+					<power />
+					<apply id="largebracket">
+						<times />
+						<apply id="3overroot32pi">
+							<divide />
+							<cn>3</cn>
+							<apply>
+								<times />
+								<apply>
+									<root />
+									<cn>32</cn>
+								</apply>
+								<ci>pi</ci>
+							</apply>
+						</apply>
+						<apply id="summationbracket">
+							<plus />
+							<cn>1</cn>
+							<apply id="summation">
+								<sum />
+								<bvar>
+									<ci>i</ci>
+								</bvar>
+								<lowlimit>
+									<cn>1</cn>
+								</lowlimit>
+								<uplimit>
+									<ci>theta</ci>
+								</uplimit>
+								<apply>
+									<selector />
+									<ci type="vector">n</ci>
+									<ci>i</ci>
+								</apply>
+							</apply>
+						</apply>
+					</apply>
+					<apply id="denominator.exponent">
+						<divide />
+						<apply>
+							<minus />
+							<ci>s</ci>
+							<cn>3</cn>
+						</apply>
+						<cn>3</cn>
+					</apply>
+				</apply>
+			</apply>
+		</apply>
+	</apply>
+</math>

src/test/resources/org/xmlcml/cml/forcefield/kk/term2.xml

+<math display='block'>
+
+	<apply id="term2">
+		<divide />
+		<apply id="term2.numerator">
+			<times />
+			<ci>pi</ci>
+			<apply>
+				<root />
+				<cn>32</cn>
+			</apply>
+		</apply>
+		<apply id="term2.denominator">
+			<times />
+			<apply id="term2.sminus3">
+				<minus />
+				<ci>s</ci>
+				<cn>3</cn>
+			</apply>
+			<apply id="denominator.powerbracket">
+				<power />
+				<apply id="largebracket">
+					<times />
+					<apply id="3overroot32pi">
+						<divide />
+						<cn>3</cn>
+						<apply>
+							<times />
+							<apply>
+								<root />
+								<cn>32</cn>
+							</apply>
+							<ci>pi</ci>
+						</apply>
+					</apply>
+					<apply id="summationbracket">
+						<plus />
+						<cn>1</cn>
+						<apply id="summation">
+							<sum />
+							<bvar>
+								<ci>i</ci>
+							</bvar>
+							<lowlimit>
+								<cn>1</cn>
+							</lowlimit>
+							<uplimit>
+								<ci>theta</ci>
+							</uplimit>
+							<apply>
+								<selector />
+								<ci type="vector">n</ci>
+								<ci>i</ci>
+							</apply>
+						</apply>
+					</apply>
+				</apply>
+				<apply id="denominator.exponent">
+					<divide />
+					<apply>
+						<minus />
+						<ci>s</ci>
+						<cn>3</cn>
+					</apply>
+					<cn>3</cn>
+				</apply>
+			</apply>
+		</apply>
+	</apply>
+</math>