Commits

Anonymous committed 24f9115

Property calculations now working with simple data.

Now need to look at extendind to more complex properties.

  • Participants
  • Parent commits 089501d

Comments (0)

Files changed (9)

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/nwchem2compchem.xml

     
     <transform process="delete" xpath=".//@cmlx:lineCount" />
     <!-- Below to 'purge' the cml and completely remove anything that's not in the compchem dictionary -->
-    <!-- 
     <transform process="delete" xpath=".//cml:module[not(starts-with(@dictRef,'compchem:'))]" />
     <transform process="delete" xpath=".//@cmlx:templateRef" />
     <transform process="delete" xpath=".//cml:module/text()" />
     <transform process="delete" xpath="//cml:list[count(*)=0]" />
     <transform process="delete" xpath="//cml:list[count(*)=0]" />
     <transform process="delete" xpath="//@id[starts-with(.,'copy')]" />
-    -->
-        
         
 </transformList>    
  

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/geometry.xml

 newline="$"
 pattern='\s*Geometry \".*\" -> \".*\"\s*$\s+\-+.*'
 endOffset="0"
-endPattern="(\s*library name resolved from:.*)|(\s*Scaling coordinates for geometry.*)|(\s*Basis.*)|(\s*NWChem.*)|(\s*Task  times  cpu:.*)|(\s*\*\*\*\*\*\*\*\*\*.*)|(\s*@.*)|(\s*Total number of active.*)|(\s* angular momentum value.*)">
+endPattern="(\s*library name resolved from:.*)|(\s*Scaling coordinates for geometry.*)|(\s*Basis.*)|(\s*NWChem.*)|(\s*Task  times  cpu:.*)|(\s*\*\*\*\*\*\*\*\*\*.*)|(\s*@.*)|(\s*Total number of active.*)|(\s* angular momentum value.*)"
+endPattern2='\s*Summary of \".*\" -> \".*\" \(.*\)\s*$\s+\-+.*'
+>
 
 <!-- Printed by nwchem/src/geom/geom.F:geom_print -->
 

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/module.xml

   name="NWChem Module" 
   repeat="*"
   pattern     = "\s*NWChem .* Module\s*"
-  pattern2     = "\s*Direct MP2\s*$\s*------+\s*"
+  pattern2    = "\s*Direct MP2\s*$\s*------+\s*"
   endPattern  = "\s*((NWChem Geometry Optimization)|(NWChem .* Module))\s*"
   endPattern2 = "\s*.\sStep\s+Energy\s+Delta\sE.*"
   endPattern3 = "\s*Direct MP2\s*"

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/nwchem.job.xml

 
     <templateList xmlns:xi="http://www.w3.org/2001/XInclude">
        <xi:include href="geomopt.xml"/>
+       <xi:include href="property.module.xml"/>
        <xi:include href="module.xml"/>
     </templateList>
 

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/property.module.xml

                                 -------------------
 
   </comment>
- 
+  
   <record repeat="4"/>
   <record id="title">\s*{X,compchem:title}\s*</record>
   
+  <!-- Can delete title as get it from calc 
+  <transform process="pullupSingleton"
+  xpath="./cml:list[@cmlx:templateRef='title']"
+  />
+  -->
+  <transform process="delete"
+  xpath="./cml:list[@cmlx:templateRef='title']"
+  />
+  
   <templateList xmlns:xi="http://www.w3.org/2001/XInclude">
   
     <xi:include href="geometry.xml"/>
   
     <transform process="delete" xpath=".//cml:list[@cmlx:templateRef='missingID']"/>
     
+   <!--  Identify as a calculation -->
+   <transform process="addDictRef" 
+   xpath="."
+   value="compchem:calculation"
+   />
+   <transform process="addId" 
+   xpath="."
+   value="propertyCalculation"
+   />
+    
     <!-- Copy in calc init module and change task -->
     <transform process="copy"
     xpath="./cml:module[@dictRef='compchem:calculation']/cml:module[@dictRef='compchem:initialization']"
     xpath="./cml:module[@cmlx:templateRef='basisSummary']"
     />
     
+    
+    <!-- Copy in calc final module -->
+    <transform process="copy"
+    xpath="./cml:module[@dictRef='compchem:calculation']/cml:module[@dictRef='compchem:finalization']"
+    to="."
+    />
   
   <comment class="example.output" id="propertyModule">
 <module/>

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/transform.environment.xml

   <transform process="copyRelative"
   xpath="./cml:module[@cmlx:templateRef='nwchem_job'][position() = 1]/cml:module[@id='environment']" 
   to="../../cml:module[@cmlx:templateRef='nwchem_job'][position() &gt; 1]"
+  position="1"
   />
      
 </transformList>  

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/transform.final.xml

 <!-- ================ finalization ================================= -->
 
 
-  <transform process="addChild"
+<!--   <transform process="addChild"
   xpath="//cml:module[@id='job']"
   elementName="cml:module"
   id="finalization"
   dictRef="compchem:finalization"
+  /> -->
+  
+  <!-- Select last top-level calculation and copy the finalization module -->
+  <transform process="copyRelative"
+  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='nwchemModule'][position()=last()]/cml:module[@dictRef='compchem:calculation'][position()=last()]/cml:module[@dictRef='compchem:finalization']"
+  to="../../.."
   />
   
-  <!-- Select last top-level calculation and copy the contents finalization module -->
-  <transform process="copyRelative"
-  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='nwchemModule'][position()=last()]/cml:module[@dictRef='compchem:calculation'][position()=last()]/cml:module[@dictRef='compchem:finalization']/*"
-  to="../../../../cml:module[@id='finalization']"
-  />
-  
-  <!-- FIXME For geometry optimisations we just assume the above fails - as the geometry optimisation is not within
-  a nwchemModule, so we just use a different xpath - should really be more careful. -->
-    <transform process="copyRelative"
+   <!-- Geometry optimisations and property calculations are different as not contained within nwchemModule -->
+<!--     <transform process="copyRelative"
   xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='geomopt']/cml:module[@dictRef='compchem:finalization']/child::*[self::cml:propertyList or self::cml:molecule[@id='molgeom']]"
   to="../../../cml:module[@id='finalization']"
+  /> -->
+    <transform process="copyRelative"
+  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='geomopt' or @cmlx:templateRef='propertyModule']/cml:module[@dictRef='compchem:finalization']"
+  to="../.."
   />
   
 </transformList>

jc-compchem-nwchem/src/main/resources/org/xmlcml/cml/converters/compchem/nwchem/log/templates/transform.initial.xml

   xpath=".//@flag"
   />
    
-   <!-- FIXME - when we can do a test for the geometry optimisation, we can do this better. For now we just
-   assume the above failed and do our own -->
+   <!-- Geometry optimisations and property calculations are different as not contained within nwchemModule -->
+   
+   <!-- Geometry optimisation -->
    <!--  parameters -->
    <transform process="copyRelative"
   xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='geomopt']/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter"        
    <transform process="copyRelative"
   xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='geomopt']/cml:module[@dictRef='compchem:initialization']/cml:list[@dictRef='compchem:dftFunctional']"        
   to="../../../cml:module[@id='jobInitialization']"
+  />
+  
+  <!-- Property Calculation -->
+   <!--  parameters -->
+   <transform process="copyRelative"
+  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='propertyModule']/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter"        
+  to="../../../../cml:module[@id='jobInitialization']/cml:parameterList"
   /> 
-
+  <!--  basisSet -->
+   <transform process="copyRelative"
+  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='propertyModule']/cml:module[@dictRef='compchem:initialization']/cml:list[@dictRef='compchem:basisSet']"        
+  to="../../../cml:module[@id='jobInitialization']"
+  />
+  <!--  dftFunctional -->
+   <transform process="copyRelative"
+  xpath="./cml:module[@id='jobList1']/cml:module[@id='job']/cml:module[@cmlx:templateRef='propertyModule']/cml:module[@dictRef='compchem:initialization']/cml:list[@dictRef='compchem:dftFunctional']"        
+  to="../../../cml:module[@id='jobInitialization']"
+  />
 </transformList>

jc-compchem-nwchem/src/test/java/org/xmlcml/cml/converters/compchem/nwchem/log/NWChemLog2CompchemConverterTest.java

         assertEquals("-38.916059261199", nodes.get(0).getValue());
         
     }
+    
+    @Test
+    public void testScfAndDftProperties() throws Exception {
+        Document doc = convertFile( FILE_DIRECTORY+"h2o_props.nwo" );
+        
+        // Check we have three jobs
+        List<Node> nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job']", CMLConstants.CML_XPATH);
+        assertFalse(nodes.isEmpty());
+        assertEquals(2, nodes.size());
+//        
+//        //1st job: compchem:method
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=1]/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter[@dictRef='compchem:method']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("scf", nodes.get(0).getValue());
+//        
+//        //1st job: compchem:task
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=1]/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter[@dictRef='compchem:task']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("energy", nodes.get(0).getValue());
+//        
+//        //1st job: compchem:basisSetLabel
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=1]/cml:module[@dictRef='compchem:initialization']/cml:list[@dictRef='compchem:basisSet']/cml:scalar[@dictRef='compchem:basisSetLabel']/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("6-31g**", nodes.get(0).getValue());
+//        
+//        // 1st Job - Final Energy
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=1]/cml:module[@dictRef='compchem:finalization']/cml:propertyList/cml:property[@dictRef='compchem:totalEnergy']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("-38.857160053103", nodes.get(0).getValue());
+//        
+//        //2nd job: compchem:method
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter[@dictRef='compchem:method']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("mcscf", nodes.get(0).getValue());
+//        
+//        //2nd job: compchem:task
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter[@dictRef='compchem:task']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("geometry_optimization", nodes.get(0).getValue());
+//        
+//        //2nd job: compchem:basisSetLabel
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:initialization']/cml:list[@dictRef='compchem:basisSet']/cml:scalar[@dictRef='compchem:basisSetLabel']/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("6-31g**", nodes.get(0).getValue());
+//        
+//        // Get z coordinate of first atom to test we have the correct molecule
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:initialization']/cml:molecule/cml:atomArray/cml:atom[position()=1]/@z3", CMLConstants.CML_XPATH);
+//        assertEquals(1, nodes.size());
+//        assertEquals("0.205", nodes.get(0).getValue());
+//        
+//        // 2nd Job - Final Energy
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:finalization']/cml:propertyList/cml:property[@dictRef='compchem:totalEnergy']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("-38.95876065", nodes.get(0).getValue());
+//        
+//        
+//        // 2nd Job final molecule - Get z coordinate of first atom to test we have the correct molecule
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=2]/cml:module[@dictRef='compchem:finalization']/cml:molecule/cml:atomArray/cml:atom[position()=1]/@z3", CMLConstants.CML_XPATH);
+//        assertEquals(1, nodes.size());
+//        assertEquals("0.23336589", nodes.get(0).getValue());
+//        
+//        //3rd job: compchem:method
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=3]/cml:module[@dictRef='compchem:initialization']/cml:parameterList/cml:parameter[@dictRef='compchem:method']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("mcscf", nodes.get(0).getValue());
+//        
+//        
+//        // Get z coordinate of first atom to test we have the correct molecule
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=3]/cml:module[@dictRef='compchem:initialization']/cml:molecule/cml:atomArray/cml:atom[position()=1]/@z3", CMLConstants.CML_XPATH);
+//        assertEquals(1, nodes.size());
+//        assertEquals("0.23336589", nodes.get(0).getValue());
+//        
+//        // 3rd Job - Final Energy
+//        nodes = CMLUtil.getQueryNodes(doc, "/cml:*[@convention='convention:compchem']/cml:module[@dictRef='compchem:jobList']/cml:module[@dictRef='compchem:job' and position()=3]/cml:module[@dictRef='compchem:finalization']/cml:propertyList/cml:property[@dictRef='compchem:totalEnergy']/cml:scalar/text()", CMLConstants.CML_XPATH);
+//        assertFalse(nodes.isEmpty());
+//        assertEquals("-38.916059261199", nodes.get(0).getValue());
+        
+    }
 }