1. petermr
  2. jumboconverters-molecule

Commits

petermr  committed 243518a

debugging poms

  • Participants
  • Parent commits fce630b
  • Branches default

Comments (0)

Files changed (51)

File jc-molecule-all/.classpath

View file
  • Ignore whitespace
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
-	<classpathentry kind="output" path="bin"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
 </classpath>

File jc-molecule-all/.settings/org.eclipse.jdt.core.prefs

View file
  • Ignore whitespace
-#Mon Feb 06 11:51:53 GMT 2012
+#Sat Feb 18 11:29:41 GMT 2012
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.6
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6

File jc-molecule-all/pom.xml

View file
  • Ignore whitespace
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
-        <groupId>cml</groupId>
         <artifactId>jc-molecule</artifactId>
         <version>0.3-SNAPSHOT</version>
+        <groupId>org.xml-cml.jc</groupId>
     </parent>
 
     <artifactId>jc-molecule-all</artifactId>
 	
     <dependencies>
         <dependency>
-            <groupId>cml</groupId>
+            <groupId>${jc.groupId}</groupId>
             <artifactId>jc-molecule-cml</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>cml</groupId>
+            <groupId>${jc.groupId}</groupId>
             <artifactId>jc-molecule-mdl</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>cml</groupId>
+            <groupId>${jc.groupId}</groupId>
             <artifactId>jc-molecule-pubchem</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
-            <groupId>cml</groupId>
+            <groupId>${jc.groupId}</groupId>
             <artifactId>jc-molecule-xyz</artifactId>
             <version>${project.version}</version>
         </dependency>

File jc-molecule-axyz/.classpath

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

File jc-molecule-axyz/.project

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jc-molecule-xyz</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>

File jc-molecule-axyz/.settings/org.eclipse.core.resources.prefs

View file
  • Ignore whitespace
+#Wed Feb 15 21:55:40 GMT 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/<project>=UTF-8

File jc-molecule-axyz/.settings/org.eclipse.jdt.core.prefs

View file
  • Ignore whitespace
+#Sat Feb 11 21:06:58 GMT 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6

File jc-molecule-axyz/.settings/org.eclipse.m2e.core.prefs

View file
  • Ignore whitespace
+#Wed Jan 04 18:20:05 GMT 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

File jc-molecule-axyz/pom.xml

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.xml-cml.jc</groupId>
+		<artifactId>jc-molecule</artifactId>
+		<version>0.3-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>jc-molecule-axyz</artifactId>
+	<name>jc-molecule-axyz</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-top-core</artifactId>
+            <version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-molecule-cml</artifactId>
+            <version>${project.version}</version>
+		</dependency>
+
+	</dependencies>
+</project>

File jc-molecule-axyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/CML2XYZConverter.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.xyz;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import nu.xom.Element;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.xmlcml.cml.base.CMLBuilder;
+import org.xmlcml.cml.base.CMLElement;
+import org.xmlcml.cml.base.CMLElement.CoordinateType;
+import org.xmlcml.cml.converters.AbstractConverter;
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.cml.CMLCommon;
+import org.xmlcml.cml.converters.cml.CMLSelector;
+import org.xmlcml.cml.element.CMLAtom;
+import org.xmlcml.cml.element.CMLMolecule;
+
+public class CML2XYZConverter extends AbstractConverter implements
+		Converter {
+
+	private static final Logger LOG = Logger.getLogger(CML2XYZConverter.class);
+	static {
+		LOG.setLevel(Level.INFO);
+	}
+	/**
+	 * converts a CML object to XYZ. assumes a single CMLMolecule as descendant
+	 * of root
+	 * 
+	 * @param xml
+	 */
+	@Override
+	public List<String> convertToText(Element xml) {
+		CMLElement cml = CMLBuilder.ensureCML(xml);
+		CMLMolecule molecule = new CMLSelector(cml).getToplevelMoleculeDescendant(true);
+		List<String> lines = new ArrayList<String>();
+		if (molecule != null) {
+			lines = convertToText(molecule);
+		}
+		return lines;
+	}
+
+	private List<String> convertToText(CMLMolecule molecule) {
+		if (!molecule.hasCoordinates(CoordinateType.CARTESIAN)) {
+			throw new RuntimeException("Molecule has no 3D coordinates");
+		}
+		List<String> lines = new ArrayList<String>();
+		lines.add(str(molecule.getAtomCount()));
+		lines.add(molecule.getTitle());
+		for (CMLAtom atom : molecule.getAtoms()) {
+			StringBuilder sb = new StringBuilder();
+			sb.append(atom.getElementType()).append(" ").append(
+					str(atom.getX3())).append(" ").append(str(atom.getY3()))
+					.append(" ").append(str(atom.getZ3()));
+			lines.add(sb.toString());
+		}
+		return lines;
+	}
+
+	public MimeType getInputType() {
+		return CMLCommon.CML_TYPE;
+	}
+	
+	public MimeType getOutputType() {
+		return XYZModule.XYZ_TYPE;
+	}
+	
+	public String getDescription() {
+		return "convert CML to XYZ";
+	}
+
+}

File jc-molecule-axyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/XYZ2CMLConverter.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.xyz;
+
+import java.util.List;
+import java.util.StringTokenizer;
+
+import nu.xom.Element;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.xmlcml.cml.converters.AbstractConverter;
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.cml.CMLCommon;
+import org.xmlcml.cml.element.CMLAtom;
+import org.xmlcml.cml.element.CMLCml;
+import org.xmlcml.cml.element.CMLMolecule;
+import org.xmlcml.euclid.Util;
+
+public class XYZ2CMLConverter extends AbstractConverter implements
+		Converter {
+
+	private static final Logger LOG = Logger.getLogger(XYZ2CMLConverter.class);
+	static {
+		LOG.setLevel(Level.INFO);
+	};
+	
+	
+	/**
+	 * converts an XYZ object to CML. returns cml:cml/cml:molecule
+	 * 
+	 * @param lines
+	 */
+	public Element convertToXML(List<String> lines) {
+		CMLMolecule molecule = new CMLMolecule();
+		int nline = 0;
+		int natoms = 0;
+		String s = lines.get(nline++);
+		try {
+			natoms = Integer.parseInt(s.trim());
+		} catch (NumberFormatException e) {
+			throw new RuntimeException("Bad atom count: " + s);
+		}
+
+		String title = lines.get(nline++);
+		molecule.setTitle(title);
+		for (int i = 0; i < natoms; i++) {
+			String line = lines.get(nline++);
+			if (line == null || line.trim().length() == 0) {
+				throw new RuntimeException("too few lines; ended after "
+						+ nline + "; expected " + natoms + 2);
+			}
+			CMLAtom atom = new CMLAtom();
+			atom.setId("a" + (i + 1));
+			StringTokenizer st = new StringTokenizer(line);
+			if (st.countTokens() != 4) {
+				throw new RuntimeException("Bad line (" + (i + 1)
+						+ ") - found (" + line + ")");
+			}
+			atom.setElementType(st.nextToken());
+			atom.setX3(Util.getDouble(st.nextToken()));
+			atom.setY3(Util.getDouble(st.nextToken()));
+			atom.setZ3(Util.getDouble(st.nextToken()));
+			molecule.addAtom(atom);
+		}
+		CMLCml cml = new CMLCml();
+		cml.appendChild(molecule);
+//		cml.debug("CML2XYZ");
+		return cml;
+	}
+
+	public MimeType getInputType() {
+		return XYZModule.XYZ_TYPE;
+	}
+	
+	public MimeType getOutputType() {
+		return CMLCommon.CML_TYPE;
+	}
+	
+	public String getDescription() {
+		return "convert XYZ to CML";
+	}
+
+}

File jc-molecule-axyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/XYZModule.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.xyz;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.MimeType.ObjectType;
+import org.xmlcml.cml.converters.registry.AbstractConverterModule;
+
+/**
+ * @author Sam Adams
+ */
+public class XYZModule extends AbstractConverterModule {
+
+	public static final MimeType XYZ_TYPE = new MimeType("chemical/x-xyz", ObjectType.TEXT, "xyz");
+	private static final String PREFIX = "xyz";
+	
+    public XYZModule(){
+    }
+    
+    public String getPrefix() {
+    	return PREFIX;
+    }
+
+	public List<Converter> getConverterList() {
+		if (converterList == null) {
+			converterList = new ArrayList<Converter>();
+			converterList.add(new XYZ2CMLConverter());
+			converterList.add(new CML2XYZConverter());
+		}
+		return converterList;
+	}
+
+	public List<MimeType> getMimeTypeList() {
+		if (mimeTypeList == null) {
+			mimeTypeList = new ArrayList<MimeType>();
+			mimeTypeList.add(XYZ_TYPE);
+		}
+		return mimeTypeList;
+	}
+	
+	
+}

File jc-molecule-axyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/package-info.java

View file
  • Ignore whitespace
+/** 
+XYZ simple molecule format
+*/
+package org.xmlcml.cml.converters.molecule.xyz;

File jc-molecule-axyz/src/main/resources/META-INF/jumbo-converters

View file
  • Ignore whitespace
+org.xmlcml.cml.converters.molecule.xyz.XYZModule;

File jc-molecule-axyz/src/test/java/org/xmlcml/cml/converters/molecule/xyz/RegressionTest.java

View file
  • Ignore whitespace
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.xmlcml.cml.converters.molecule.xyz;
+
+
+import org.junit.Ignore;
+
+import org.junit.Test;
+import org.xmlcml.cml.converters.testutils.RegressionSuite;
+
+/**
+ *
+ * @author ojd20
+ */
+public class RegressionTest {
+
+   @Test
+   @Ignore
+   public void xyz2cml() {
+      RegressionSuite.run("molecule/xyz/xyz2cml", "xyz", "cml",
+                          new XYZ2CMLConverter());
+   }
+
+   @Test
+   @Ignore
+   public void cml2xyz() {
+      RegressionSuite.run("molecule/xyz/cml2xyz", "cml", "xyz",
+                          new CML2XYZConverter());
+   }
+}

File jc-molecule-cml/pom.xml

View file
  • Ignore whitespace
 	<modelVersion>4.0.0</modelVersion>
 
 	<parent>
-		<groupId>cml</groupId>
+		<groupId>org.xml-cml.jc</groupId>
 		<artifactId>jc-molecule</artifactId>
 		<version>0.3-SNAPSHOT</version>
 	</parent>
 
 	<dependencies>
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>org.xml-cml.jc</groupId>
 			<artifactId>jc-top-core</artifactId>
             <version>${project.version}</version>
 		</dependency>
 		
+
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-top-testutils</artifactId>
+            <version>${project.version}</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 </project>

File jc-molecule-cml/src/main/java/org/xmlcml/cml/converters/molecule/CMLModule.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.MimeType.ObjectType;
+import org.xmlcml.cml.converters.molecule.cml.CML2CMLConverter;
+import org.xmlcml.cml.converters.registry.AbstractConverterModule;
+
+/**
+ * @author Sam Adams
+ */
+public class CMLModule extends AbstractConverterModule {
+
+	public static final MimeType MOL_TYPE = new MimeType("chemical/x-mdl-molfile", ObjectType.TEXT, "mol");
+	public static final MimeType SDF_TYPE = new MimeType("chemical/x-mdl-sdffile", ObjectType.TEXT, "sdf");
+	private static final String PREFIX = "cml";
+	
+    public CMLModule(){
+    }
+    
+    public String getPrefix() {
+    	return PREFIX;
+    }
+
+	public List<Converter> getConverterList() {
+		if (converterList == null) {
+			converterList = new ArrayList<Converter>();
+			converterList.add(new CML2CMLConverter());
+		}
+		return converterList;
+	}
+
+	public List<MimeType> getMimeTypeList() {
+		if (mimeTypeList == null) {
+			mimeTypeList = new ArrayList<MimeType>();
+		}
+		return mimeTypeList;
+	}
+	
+	
+}

File jc-molecule-cml/src/main/java/org/xmlcml/cml/converters/molecule/MoleculeModule.java

  • Ignore whitespace
-package org.xmlcml.cml.converters.molecule;
-
-import java.util.ArrayList;
-
-import java.util.List;
-
-import org.xmlcml.cml.converters.Converter;
-import org.xmlcml.cml.converters.MimeType;
-import org.xmlcml.cml.converters.MimeType.ObjectType;
-import org.xmlcml.cml.converters.registry.AbstractConverterModule;
-
-/**
- * @author Sam Adams
- */
-public class MoleculeModule extends AbstractConverterModule {
-
-	public static final MimeType MDL_TYPE = new MimeType("chemical/x-mdl-molfile", ObjectType.TEXT, "mol");
-	public static final MimeType PUBCHEM_XML_TYPE = new MimeType("chemical/x-pubchem-xml", ObjectType.XML, "xml");
-	public static final MimeType SDF_TYPE = new MimeType("chemical/x-sdf", ObjectType.TEXT, "sdf");
-	public static final MimeType XYZ_TYPE = new MimeType("chemical/x-xyz", ObjectType.TEXT, "xyz");
-	private static final String PREFIX = "molecule";
-
-    public String getPrefix() {
-    	return PREFIX;
-    }
-
-    public MoleculeModule() {
-    	super();
-    }
-
-	public List<Converter> getConverterList() {
-//        converterList.add(new CMLEditor1());
-//        converterList.add(new CMLTransformMolecule());
-//        converterList.add(new CML2MDLConverter());
-//        converterList.add(new MDL2CMLConverter());
-//        converterList.add(new CML2SDFConverter());
-//        converterList.add(new SDF2CMLConverter());
-//        converterList.add(new PubchemXML2CMLConverter());
-//        converterList.add(new CML2XYZConverter());
-//        converterList.add(new XYZ2CMLConverter());
-		return converterList;
-	}
-
-	public List<MimeType> getMimeTypeList() {
-		if (mimeTypeList == null) {
-			mimeTypeList = new ArrayList<MimeType>();
-			mimeTypeList.add(MDL_TYPE);
-			mimeTypeList.add(PUBCHEM_XML_TYPE);
-			mimeTypeList.add(SDF_TYPE);
-			mimeTypeList.add(XYZ_TYPE);
-		}
-		return mimeTypeList;
-	}
-	
-}

File jc-molecule-cml/src/main/resources/META-INF/jumbo-converters

View file
  • Ignore whitespace
-org.xmlcml.cml.converters.chemdraw.ChemdrawConverters
+org.xmlcml.cml.converters.molecule.CMLModule

File jc-molecule-mdl/pom.xml

View file
  • Ignore whitespace
 	<modelVersion>4.0.0</modelVersion>
 
 	<parent>
-		<groupId>cml</groupId>
+		<groupId>org.xml-cml.jc</groupId>
 		<artifactId>jc-molecule</artifactId>
 		<version>0.3-SNAPSHOT</version>
 	</parent>
 
 	<dependencies>
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>${jc.groupId}</groupId>
 			<artifactId>jc-top-core</artifactId>
             <version>${project.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>${jc.groupId}</groupId>
 			<artifactId>jc-molecule-cml</artifactId>
             <version>${project.version}</version>
 		</dependency>
+		
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-top-testutils</artifactId>
+            <version>${project.version}</version>
+			<scope>test</scope>
+		</dependency>
+		
 	</dependencies>
 </project>

File jc-molecule-mdl/src/main/java/org/xmlcml/cml/converters/molecule/mdl/CML2MDLConverter.java

View file
  • Ignore whitespace
 import org.xmlcml.cml.converters.MimeType;
 import org.xmlcml.cml.converters.cml.CMLCommon;
 import org.xmlcml.cml.converters.cml.CMLSelector;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
 import org.xmlcml.cml.converters.molecule.mdl.MDLConverter.CoordType;
 import org.xmlcml.cml.element.CMLMolecule;
 
 	}
 	
 	public MimeType getOutputType() {
-		return MoleculeModule.MDL_TYPE;
+		return MDLModule.MOL_TYPE;
 	}
 	
 	public String getDescription() {

File jc-molecule-mdl/src/main/java/org/xmlcml/cml/converters/molecule/mdl/CML2SDFConverter.java

View file
  • Ignore whitespace
 import org.xmlcml.cml.converters.MimeType;
 import org.xmlcml.cml.converters.cml.CMLCommon;
 import org.xmlcml.cml.converters.cml.CMLSelector;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
 import org.xmlcml.cml.element.CMLMolecule;
 import org.xmlcml.cml.element.CMLProperty;
 import org.xmlcml.cml.element.CMLScalar;
 	}
 	
 	public MimeType getOutputType() {
-		return MoleculeModule.SDF_TYPE;
+		return MDLModule.SDF_TYPE;
 	}
 	
 	public String getDescription() {

File jc-molecule-mdl/src/main/java/org/xmlcml/cml/converters/molecule/mdl/MDL2CMLConverter.java

View file
  • Ignore whitespace
 import org.xmlcml.cml.converters.AbstractConverter;
 import org.xmlcml.cml.converters.MimeType;
 import org.xmlcml.cml.converters.cml.CMLCommon;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
 import org.xmlcml.cml.element.CMLCml;
 import org.xmlcml.cml.element.CMLMolecule;
 
 	}
 	
 	public MimeType getInputType() {
-		return MoleculeModule.MDL_TYPE;
+		return MDLModule.MOL_TYPE;
 	}
 	
 	public MimeType getOutputType() {

File jc-molecule-mdl/src/main/java/org/xmlcml/cml/converters/molecule/mdl/MDLModule.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.mdl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.MimeType.ObjectType;
+import org.xmlcml.cml.converters.registry.AbstractConverterModule;
+
+/**
+ * @author Sam Adams
+ */
+public class MDLModule extends AbstractConverterModule {
+
+	public static final MimeType MOL_TYPE = new MimeType("chemical/x-mdl-molfile", ObjectType.TEXT, "mol");
+	public static final MimeType SDF_TYPE = new MimeType("chemical/x-mdl-sdffile", ObjectType.TEXT, "sdf");
+	private static final String PREFIX = "mol";
+	
+    public MDLModule(){
+    }
+    
+    public String getPrefix() {
+    	return PREFIX;
+    }
+
+	public List<Converter> getConverterList() {
+		if (converterList == null) {
+			System.out.println("MDLMODULE");
+			converterList = new ArrayList<Converter>();
+			converterList.add(new CML2MDLConverter());
+			converterList.add(new CML2SDFConverter());
+			converterList.add(new MDL2CMLConverter());
+			converterList.add(new SDF2CMLConverter());
+		}
+		return converterList;
+	}
+
+	public List<MimeType> getMimeTypeList() {
+		if (mimeTypeList == null) {
+			mimeTypeList = new ArrayList<MimeType>();
+			mimeTypeList.add(MOL_TYPE);
+			mimeTypeList.add(SDF_TYPE);
+		}
+		return mimeTypeList;
+	}
+	
+	
+}

File jc-molecule-mdl/src/main/java/org/xmlcml/cml/converters/molecule/mdl/SDF2CMLConverter.java

View file
  • Ignore whitespace
 package org.xmlcml.cml.converters.molecule.mdl;
 
 import java.io.File;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import org.xmlcml.cml.element.CMLScalar;
 import org.xmlcml.cml.interfacex.HasDataType;
 import org.xmlcml.cml.interfacex.HasDictRef;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
 
 public class SDF2CMLConverter extends AbstractConverter implements
 		Converter {
 	}
 	
 	public MimeType getInputType() {
-		return MoleculeModule.SDF_TYPE;
+		return MDLModule.SDF_TYPE;
 	}
 	
 	public MimeType getOutputType() {

File jc-molecule-mdl/src/main/resources/META-INF/jumbo-converters

View file
  • Ignore whitespace
-org.xmlcml.cml.converters.chemdraw.ChemdrawConverters
+org.xmlcml.cml.converters.molecule.mdl.MDLModule

File jc-molecule-mdl/src/test/java/org/xmlcml/cml/converters/molecule/mdl/RegressionTest.java

View file
  • Ignore whitespace
 import org.junit.Ignore;
 import org.junit.Test;
 import org.xmlcml.cml.converters.testutils.RegressionSuite;
-
 /**
  *
  * @author ojd20

File jc-molecule-pubchem/pom.xml

View file
  • Ignore whitespace
 	<modelVersion>4.0.0</modelVersion>
 
 	<parent>
-		<groupId>cml</groupId>
+		<groupId>org.xml-cml.jc</groupId>
 		<artifactId>jc-molecule</artifactId>
 		<version>0.3-SNAPSHOT</version>
 	</parent>
 
 	<dependencies>
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>${jc.groupId}</groupId>
 			<artifactId>jc-molecule-cml</artifactId>
             <version>${project.version}</version>
 		</dependency>
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>${jc.groupId}</groupId>
 			<artifactId>jc-molecule-mdl</artifactId>
             <version>${project.version}</version>
 		</dependency>
 
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-top-testutils</artifactId>
+            <version>${project.version}</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 </project>

File jc-molecule-pubchem/src/main/java/org/xmlcml/cml/converters/molecule/pubchem/PubchemModule.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.pubchem;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.MimeType.ObjectType;
+import org.xmlcml.cml.converters.registry.AbstractConverterModule;
+
+/**
+ * @author Sam Adams
+ */
+public class PubchemModule extends AbstractConverterModule {
+
+	public static final MimeType PUBCHEM_XML_TYPE = new MimeType("chemical/x-pubchem-xml", ObjectType.XML, "pubchem-xml");
+	private static final String PREFIX = "pubchem.xml";
+	
+    public PubchemModule(){
+    }
+    
+    public String getPrefix() {
+    	return PREFIX;
+    }
+
+	public List<Converter> getConverterList() {
+		if (converterList == null) {
+			converterList = new ArrayList<Converter>();
+			converterList.add(new PubchemXML2CMLConverter());
+		}
+		return converterList;
+	}
+
+	public List<MimeType> getMimeTypeList() {
+		if (mimeTypeList == null) {
+			mimeTypeList = new ArrayList<MimeType>();
+			mimeTypeList.add(PUBCHEM_XML_TYPE);
+		}
+		return mimeTypeList;
+	}
+	
+	
+}

File jc-molecule-pubchem/src/main/java/org/xmlcml/cml/converters/molecule/pubchem/PubchemXML2CMLConverter.java

View file
  • Ignore whitespace
 import org.xmlcml.cml.converters.MimeType;
 import org.xmlcml.cml.converters.Util;
 import org.xmlcml.cml.converters.cml.CMLCommon;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
 import org.xmlcml.cml.element.CMLAtom;
 import org.xmlcml.cml.element.CMLAtomParity;
 import org.xmlcml.cml.element.CMLBond;
    }
 
 	public MimeType getInputType() {
-		return MoleculeModule.PUBCHEM_XML_TYPE;
+		return PubchemModule.PUBCHEM_XML_TYPE;
 	}
 	
 	public MimeType getOutputType() {

File jc-molecule-pubchem/src/main/resources/META-INF/jumbo-converters

View file
  • Ignore whitespace
-org.xmlcml.cml.converters.chemdraw.ChemdrawConverters
+org.xmlcml.cml.converters.molecule.pubchem.PubchemModule

File jc-molecule-registry/.classpath

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

File jc-molecule-registry/.project

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jc-molecule-registry</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>

File jc-molecule-registry/.settings/org.eclipse.core.resources.prefs

View file
  • Ignore whitespace
+#Sun Feb 19 14:13:28 GMT 2012
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding/<project>=UTF-8

File jc-molecule-registry/.settings/org.eclipse.jdt.core.prefs

View file
  • Ignore whitespace
+#Sun Feb 19 12:41:23 GMT 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6

File jc-molecule-registry/.settings/org.eclipse.m2e.core.prefs

View file
  • Ignore whitespace
+#Sun Feb 19 12:41:22 GMT 2012
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

File jc-molecule-registry/pom.xml

View file
  • Ignore whitespace
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.xml-cml.jc</groupId>
+		<artifactId>jc-molecule</artifactId>
+		<version>0.3-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>jc-molecule-registry</artifactId>
+	<name>jc-molecule-registry</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>${jc.groupId}</groupId>
+			<artifactId>jc-molecule-all</artifactId>
+            <version>${project.version}</version>
+		</dependency>
+	</dependencies>
+</project>

File jc-molecule-registry/src/main/java/org/xmlcml/cml/converters/molecule/registry/MoleculeConverterRegistry.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.registry;
+
+import org.xmlcml.cml.converters.registry.ConverterRegistry;
+
+/**
+ * @author Sam Adams
+ */
+public class MoleculeConverterRegistry extends ConverterRegistry {
+
+    /** create singleton registry
+     */
+    private static MoleculeConverterRegistry MOLECULE_CONVERTER_REGISTRY = null;
+    
+    public static synchronized MoleculeConverterRegistry getDefaultConverterRegistry() {
+    	if (MOLECULE_CONVERTER_REGISTRY == null) {
+    		MOLECULE_CONVERTER_REGISTRY = new MoleculeConverterRegistry(MoleculeConverterRegistry.class.getClassLoader());
+    		MOLECULE_CONVERTER_REGISTRY.populateAndRegister();
+    	}
+    	return MOLECULE_CONVERTER_REGISTRY;
+    }
+    
+    public MoleculeConverterRegistry(ClassLoader classLoader) {
+    	super(classLoader);
+    }
+
+    public MoleculeConverterRegistry(Class clazz) {
+    	super(clazz);
+    }
+
+    
+}

File jc-molecule-registry/src/test/java/org/xmlcml/cml/converters/molecule/registry/MoleculeConverterRegistryTest.java

View file
  • Ignore whitespace
+package org.xmlcml.cml.converters.molecule.registry;
+
+import static org.junit.Assert.assertNull;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xmlcml.cml.converters.Converter;
+import org.xmlcml.cml.converters.MimeType;
+import org.xmlcml.cml.converters.cml.CML2CMLLiteConverter;
+import org.xmlcml.cml.converters.cml.CMLCommon;
+import org.xmlcml.cml.converters.registry.ConverterRegistry;
+import org.xmlcml.cml.converters.registry.TypePair;
+import org.xmlcml.cml.converters.molecule.mdl.MDLModule;
+
+//@Ignore
+public class MoleculeConverterRegistryTest {
+
+	String CML = "chemical/x-cml";
+	String CDX = "chemical/x-cdx";
+	String FOO = "chemical/x-foo";
+	TypePair PAIR_OK  = new TypePair(FOO, CML);
+	TypePair PAIR_MISSING  = new TypePair(CML, CDX);
+	
+    @Test
+    public void testMap() {
+    	Map<TypePair, List<Converter>> map = MoleculeConverterRegistry.getDefaultConverterRegistry().getMap();
+    	Assert.assertNotNull(map);
+    	// size will change as more are added
+    	Assert.assertEquals(2, map.size());
+    }
+
+    @Test
+    public void testList() {
+    	List<Converter> converterList = MoleculeConverterRegistry.getDefaultConverterRegistry().getConverterList();
+    	Assert.assertNotNull(converterList);
+    	Assert.assertEquals(2, converterList.size());
+    }
+
+    @Test
+    public void testList1() {
+    	List<Converter> converterList = MoleculeConverterRegistry.getDefaultConverterRegistry().getConverterList();
+    	boolean found = false;
+    	for (Converter converter : converterList) {
+    		if (CML2CMLLiteConverter.class.equals(converter.getClass())) {
+    			found = true;
+    			break;
+    		}
+    	}
+    	Assert.assertTrue("converter", found);
+    }
+
+    @Test
+    public void testMap1() {
+    	Map<TypePair, List<Converter>> map = MoleculeConverterRegistry.getDefaultConverterRegistry().getMap();
+    	Assert.assertTrue(map.containsKey(PAIR_OK));
+    	Assert.assertFalse(map.containsKey(PAIR_MISSING));
+    	for (TypePair typePair1 : map.keySet()) {
+    		System.out.println(typePair1);
+    	}
+    }
+
+    @Test
+    public void testFindConverter() {
+    	List<Converter> converters = MoleculeConverterRegistry.getDefaultConverterRegistry().findConverters(
+    			MDLModule.MOL_TYPE.getMimeType(), CMLCommon.CML_TYPE.getMimeType());
+    	Assert.assertNotNull("mdl", converters);
+    	for (Converter converter : converters) {
+    		System.out.println("Converter: "+converter);
+    	}
+    	Assert.assertEquals("mdl", 1, converters.size());
+    	Assert.assertEquals("mdl", "org.xmlcml.cml.converters.molecules.mdl.MDL2CMLConverter", converters.get(0).getClass().getName());
+    }
+
+    @Test
+    public void testFindConverter1() {
+    	List<Converter> converters = MoleculeConverterRegistry.getDefaultConverterRegistry().findConverters(CML, CML);
+    	Assert.assertNotNull("cml", converters);
+//    	for (Converter converter : converters) {
+//    		System.out.println(converter);
+//    	}
+    	Assert.assertEquals("cml", 1, converters.size());
+    }
+
+	@Test
+	public void testRegistryLoadsConverterList() {
+		List<Converter> list = MoleculeConverterRegistry.getDefaultConverterRegistry().getConverterList();
+		assertTrue(list.size()>0);
+	}
+
+	@Test
+	public void testFindFoo2BarConverter() {
+		List<Converter> converterList = MoleculeConverterRegistry.getDefaultConverterRegistry().findConverters("foo", "bar");
+		assertNull(converterList);
+	}
+
+	@Test
+	public void testFindTypesFromSuffix() {
+		Set<MimeType> types = MoleculeConverterRegistry.getDefaultConverterRegistry().getTypes("cml");
+		Assert.assertNotNull("get types", types);
+		Assert.assertEquals("get types", 1, types.size());
+		Assert.assertEquals("get types", "chemical/x-cml", ((MimeType)types.toArray()[0]).getMimeType());
+	}
+
+	@Test
+	public void testFindTypesFromSuffix1() {
+		Set<MimeType> types = MoleculeConverterRegistry.getDefaultConverterRegistry().getTypes("foo");
+		Assert.assertNotNull("get types", types);
+		Assert.assertEquals("types count", 1, types.size());
+		Assert.assertEquals("type", "chemical/x-foo", ((MimeType)types.toArray()[0]).getMimeType());
+	}
+
+	@Test
+	public void testFindSingleTypeFromSuffix() {
+		MimeType type = MoleculeConverterRegistry.getDefaultConverterRegistry().getSingleTypeFromSuffix("cml");
+		Assert.assertNotNull("get type", type);
+		Assert.assertEquals("get type", "chemical/x-cml", type.getMimeType());
+	}
+	
+	@Test
+	public void testSingletonConverterRegistry() {
+		Assert.assertNotNull(MoleculeConverterRegistry.getDefaultConverterRegistry());
+	}
+
+	@Test
+	public void testCreateRegistryList0() {
+		ConverterRegistry converterRegistry = new ConverterRegistry(ConverterRegistry.class.getClassLoader());
+		List<Converter> converterList = converterRegistry.getConverterList();
+		Assert.assertNotNull(converterList);
+		converterRegistry.createConvertersList();
+		converterList = converterRegistry.getConverterList();
+		Assert.assertNotNull(converterList);
+	}
+	
+	@Test
+	public void testCreateRegistryList() {
+		ConverterRegistry converterRegistry = new MoleculeConverterRegistry(MoleculeConverterRegistry.class.getClassLoader());
+		converterRegistry.populateAndRegister();
+		List<Converter> converterList = converterRegistry.getConverterList();
+		converterRegistry.createConvertersList();
+		converterList = converterRegistry.getConverterList();
+		// should at least contain org.xmlcml.cml.converters.cml.CML2CMLLiteConverter@76f2d004
+		Assert.assertTrue(converterList.size()>0);
+		boolean hasCmllite = false;
+		for (Converter converter : converterList) {
+			if (converter instanceof org.xmlcml.cml.converters.cml.CML2CMLLiteConverter) {
+				hasCmllite = true;
+				break;
+			}
+		}
+		Assert.assertTrue("has cmllite", hasCmllite);
+	}
+	
+	@Test
+	public void testSingletonConverterRegistryList0() {
+		ConverterRegistry converterRegistry = MoleculeConverterRegistry.getDefaultConverterRegistry();
+		List<Converter> converterList = converterRegistry.getConverterList();
+		Assert.assertNotNull(converterList);
+		Assert.assertEquals("converterList", 2, converterList.size());
+	}
+
+	@Test
+	public void testSingletonConverterRegistryList() {
+		List<Converter> converterList = MoleculeConverterRegistry.getDefaultConverterRegistry().getConverterList();
+		Assert.assertNotNull(converterList);
+		Assert.assertEquals("converterList", 2, converterList.size());
+	}
+
+}

File jc-molecule-xyz/.classpath

  • Ignore whitespace
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
-	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
-	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
-	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
-	<classpathentry kind="output" path="target/classes"/>
-</classpath>

File jc-molecule-xyz/.project

  • Ignore whitespace
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>jc-molecule-xyz</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.m2e.core.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.eclipse.m2e.core.maven2Nature</nature>
-	</natures>
-</projectDescription>

File jc-molecule-xyz/.settings/org.eclipse.core.resources.prefs

  • Ignore whitespace
-#Wed Feb 15 21:55:40 GMT 2012
-eclipse.preferences.version=1
-encoding//src/main/java=UTF-8
-encoding//src/main/resources=UTF-8
-encoding//src/test/java=UTF-8
-encoding//src/test/resources=UTF-8
-encoding/<project>=UTF-8

File jc-molecule-xyz/.settings/org.eclipse.jdt.core.prefs

  • Ignore whitespace
-#Sat Feb 11 21:06:58 GMT 2012
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.6

File jc-molecule-xyz/.settings/org.eclipse.m2e.core.prefs

  • Ignore whitespace
-#Wed Jan 04 18:20:05 GMT 2012
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1

File jc-molecule-xyz/pom.xml

  • Ignore whitespace
-<?xml version="1.0" encoding="UTF-8"?>
-<project
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-	<modelVersion>4.0.0</modelVersion>
-
-	<parent>
-		<groupId>cml</groupId>
-		<artifactId>jc-molecule</artifactId>
-		<version>0.3-SNAPSHOT</version>
-	</parent>
-
-	<artifactId>jc-molecule-xyz</artifactId>
-	<name>jc-molecule-xyz</name>
-
-	<dependencies>
-		<dependency>
-			<groupId>cml</groupId>
-			<artifactId>jc-top-core</artifactId>
-            <version>${project.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>cml</groupId>
-			<artifactId>jc-molecule-cml</artifactId>
-            <version>${project.version}</version>
-		</dependency>
-
-	</dependencies>
-</project>

File jc-molecule-xyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/CML2XYZConverter.java

  • Ignore whitespace
-package org.xmlcml.cml.converters.molecule.xyz;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import nu.xom.Element;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.cml.base.CMLBuilder;
-import org.xmlcml.cml.base.CMLElement;
-import org.xmlcml.cml.base.CMLElement.CoordinateType;
-import org.xmlcml.cml.converters.AbstractConverter;
-import org.xmlcml.cml.converters.Converter;
-import org.xmlcml.cml.converters.MimeType;
-import org.xmlcml.cml.converters.cml.CMLCommon;
-import org.xmlcml.cml.converters.cml.CMLSelector;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
-import org.xmlcml.cml.element.CMLAtom;
-import org.xmlcml.cml.element.CMLMolecule;
-
-public class CML2XYZConverter extends AbstractConverter implements
-		Converter {
-
-	private static final Logger LOG = Logger.getLogger(CML2XYZConverter.class);
-	static {
-		LOG.setLevel(Level.INFO);
-	}
-	/**
-	 * converts a CML object to XYZ. assumes a single CMLMolecule as descendant
-	 * of root
-	 * 
-	 * @param xml
-	 */
-	@Override
-	public List<String> convertToText(Element xml) {
-		CMLElement cml = CMLBuilder.ensureCML(xml);
-		CMLMolecule molecule = new CMLSelector(cml).getToplevelMoleculeDescendant(true);
-		List<String> lines = new ArrayList<String>();
-		if (molecule != null) {
-			lines = convertToText(molecule);
-		}
-		return lines;
-	}
-
-	private List<String> convertToText(CMLMolecule molecule) {
-		if (!molecule.hasCoordinates(CoordinateType.CARTESIAN)) {
-			throw new RuntimeException("Molecule has no 3D coordinates");
-		}
-		List<String> lines = new ArrayList<String>();
-		lines.add(str(molecule.getAtomCount()));
-		lines.add(molecule.getTitle());
-		for (CMLAtom atom : molecule.getAtoms()) {
-			StringBuilder sb = new StringBuilder();
-			sb.append(atom.getElementType()).append(" ").append(
-					str(atom.getX3())).append(" ").append(str(atom.getY3()))
-					.append(" ").append(str(atom.getZ3()));
-			lines.add(sb.toString());
-		}
-		return lines;
-	}
-
-	public MimeType getInputType() {
-		return CMLCommon.CML_TYPE;
-	}
-	
-	public MimeType getOutputType() {
-		return MoleculeModule.XYZ_TYPE;
-	}
-	
-	public String getDescription() {
-		return "convert CML to XYZ";
-	}
-
-}

File jc-molecule-xyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/XYZ2CMLConverter.java

  • Ignore whitespace
-package org.xmlcml.cml.converters.molecule.xyz;
-
-import java.util.List;
-import java.util.StringTokenizer;
-
-import nu.xom.Element;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.xmlcml.cml.converters.AbstractConverter;
-import org.xmlcml.cml.converters.Converter;
-import org.xmlcml.cml.converters.MimeType;
-import org.xmlcml.cml.converters.cml.CMLCommon;
-import org.xmlcml.cml.converters.molecule.MoleculeModule;
-import org.xmlcml.cml.element.CMLAtom;
-import org.xmlcml.cml.element.CMLCml;
-import org.xmlcml.cml.element.CMLMolecule;
-import org.xmlcml.euclid.Util;
-
-public class XYZ2CMLConverter extends AbstractConverter implements
-		Converter {
-
-	private static final Logger LOG = Logger.getLogger(XYZ2CMLConverter.class);
-	static {
-		LOG.setLevel(Level.INFO);
-	};
-	
-	
-	/**
-	 * converts an XYZ object to CML. returns cml:cml/cml:molecule
-	 * 
-	 * @param lines
-	 */
-	public Element convertToXML(List<String> lines) {
-		CMLMolecule molecule = new CMLMolecule();
-		int nline = 0;
-		int natoms = 0;
-		String s = lines.get(nline++);
-		try {
-			natoms = Integer.parseInt(s.trim());
-		} catch (NumberFormatException e) {
-			throw new RuntimeException("Bad atom count: " + s);
-		}
-
-		String title = lines.get(nline++);
-		molecule.setTitle(title);
-		for (int i = 0; i < natoms; i++) {
-			String line = lines.get(nline++);
-			if (line == null || line.trim().length() == 0) {
-				throw new RuntimeException("too few lines; ended after "
-						+ nline + "; expected " + natoms + 2);
-			}
-			CMLAtom atom = new CMLAtom();
-			atom.setId("a" + (i + 1));
-			StringTokenizer st = new StringTokenizer(line);
-			if (st.countTokens() != 4) {
-				throw new RuntimeException("Bad line (" + (i + 1)
-						+ ") - found (" + line + ")");
-			}
-			atom.setElementType(st.nextToken());
-			atom.setX3(Util.getDouble(st.nextToken()));
-			atom.setY3(Util.getDouble(st.nextToken()));
-			atom.setZ3(Util.getDouble(st.nextToken()));
-			molecule.addAtom(atom);
-		}
-		CMLCml cml = new CMLCml();
-		cml.appendChild(molecule);
-//		cml.debug("CML2XYZ");
-		return cml;
-	}
-
-	public MimeType getInputType() {
-		return MoleculeModule.XYZ_TYPE;
-	}
-	
-	public MimeType getOutputType() {
-		return CMLCommon.CML_TYPE;
-	}
-	
-	public String getDescription() {
-		return "convert XYZ to CML";
-	}
-
-}

File jc-molecule-xyz/src/main/java/org/xmlcml/cml/converters/molecule/xyz/package-info.java

  • Ignore whitespace
-/** 
-XYZ simple molecule format
-*/
-package org.xmlcml.cml.converters.molecule.xyz;

File jc-molecule-xyz/src/main/resources/META-INF/jumbo-converters

  • Ignore whitespace
-org.xmlcml.cml.converters.chemdraw.ChemdrawConverters

File jc-molecule-xyz/src/test/java/org/xmlcml/cml/converters/molecule/xyz/RegressionTest.java

  • Ignore whitespace
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.xmlcml.cml.converters.molecule.xyz;
-
-
-import org.junit.Ignore;
-
-import org.junit.Test;
-import org.xmlcml.cml.converters.testutils.RegressionSuite;
-
-/**
- *
- * @author ojd20
- */
-public class RegressionTest {
-
-   @Test
-   @Ignore
-   public void xyz2cml() {
-      RegressionSuite.run("molecule/xyz/xyz2cml", "xyz", "cml",
-                          new XYZ2CMLConverter());
-   }
-
-   @Test
-   @Ignore
-   public void cml2xyz() {
-      RegressionSuite.run("molecule/xyz/cml2xyz", "cml", "xyz",
-                          new CML2XYZConverter());
-   }
-}

File pom.xml

View file
  • Ignore whitespace
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
-        <groupId>cml</groupId>
+        <groupId>org.xml-cml.jc</groupId>
         <artifactId>jc-parent</artifactId>
         <version>0.3-SNAPSHOT</version>
     </parent>
 	</repositories>
 	
     <modules>
-        <module>jc-molecule-all</module>
+        <module>jc-molecule-axyz</module>
         <module>jc-molecule-cml</module>
         <module>jc-molecule-mdl</module>
         <module>jc-molecule-pubchem</module>
-        <module>jc-molecule-xyz</module>
+        <module>jc-molecule-all</module>
+        <module>jc-molecule-registry</module>
     </modules>
 
     <dependencies>
         <dependency>
-            <groupId>cml</groupId>
+            <groupId>${jc.groupId}</groupId>
             <artifactId>jc-top-core</artifactId>
             <version>${project.version}</version>
         </dependency>
 			<artifactId>junit</artifactId>
 			<scope>test</scope>
 		</dependency>
+
 		<dependency>
-			<groupId>cml</groupId>
+			<groupId>${jc.groupId}</groupId>
 			<artifactId>jc-top-testutils</artifactId>
             <version>${project.version}</version>
 			<scope>test</scope>