Commits

petermr committed 48d53ca

changed pom to later jumbo-converters-core

Comments (0)

Files changed (4)

 			<version>0.2-SNAPSHOT</version>
 		</dependency>
 		<dependency>
+			<groupId>cml</groupId>
+			<artifactId>jumbo-converters-core</artifactId>
+			<version>0.3-SNAPSHOT</version>
+		</dependency>
+		<dependency>
 			<groupId>org.hamcrest</groupId>
 			<artifactId>hamcrest-all</artifactId>
 			<version>1.1</version>

src/main/java/org/xmlcml/cml/semcompchem/feeds/CrystaleyeMoietyFeedHandler.java

 package org.xmlcml.cml.semcompchem.feeds;
 
 import java.io.File;
+
 import java.io.InputStream;
 
 import org.apache.commons.io.FileUtils;

src/main/java/org/xmlcml/cml/semcompchem/feeds/CrystaleyeMoietyFeedReader.java

 package org.xmlcml.cml.semcompchem.feeds;
 
 import java.io.File;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.util.Map;
 
 import nu.xom.Document;
-import nu.xom.ParsingException;
-import nu.xom.ValidityException;
+import nu.xom.Element;
 
 import org.xmlcml.cml.base.CMLBuilder;
+import org.xmlcml.cml.base.CMLElement;
+import org.xmlcml.cml.base.CMLUtil;
 import org.xmlcml.cml.converters.antlr.CrystalEyeMoietyInputBuilder;
+import org.xmlcml.cml.converters.cmllite.CML2CMLLiteConverter;
 import org.xmlcml.cml.converters.freemarker.FreeMarkerWriter;
-import org.xmlcml.cml.element.CMLMolecule;
 
 import uk.ac.cam.ch.atomxom.feeds.FeedCache;
 
 	 */
 	public static void main(String[] args) throws IOException {
 		String filepath = "c:/workspace/crystaleye-moieties/";
+		boolean convertToCMLLite = true;
+		String convertInName = (convertToCMLLite) ? ".cml" : ".xml";
 		File dataDir = new File(filepath);
 
-		/*
+//		/*
 		CrystaleyeMoietyFeedReader reader = new CrystaleyeMoietyFeedReader(dataDir);
 		reader.readFeed();
-		 */
+//		 */
 
-		for (File file : dataDir.listFiles()) {
-			if (!file.getName().endsWith("xml")) {
-				continue;
+		if (convertToCMLLite) {
+			CrystaleyeMoietyFeedReader.convertToCMLLite(dataDir);
+		}
+		File[] files = dataDir.listFiles();
+		if (files != null) {
+			for (File file : files) {
+				String filename = file.getName();
+				if (filename.endsWith(convertInName)) {
+					CMLBuilder builder = new CMLBuilder();
+					Map<String, Object> model = null;
+					try {
+						Document cml = builder.build(file);
+						Element rootElement = cml.getRootElement();
+						CrystalEyeMoietyInputBuilder crystalInputBuilder = new CrystalEyeMoietyInputBuilder();
+						model = crystalInputBuilder.buildInputModel((CMLElement)rootElement);
+					} catch (Exception ex) {
+						System.out.println("Problem!: "+ex.getMessage());
+					}
+					FreeMarkerWriter writer = new FreeMarkerWriter();
+					StringWriter sw = new StringWriter();
+					writer.processTemplate("gauinput.ftl", model, sw);
+					FileWriter fw = new FileWriter(filename+".in");
+					fw.write(sw.toString());
+				}
 			}
-			CMLBuilder builder = new CMLBuilder();
-			Map<String, Object> model = null;
-			try {
-				Document cml = builder.build(file);
-				CrystalEyeMoietyInputBuilder crystalInputBuilder = new CrystalEyeMoietyInputBuilder();
-				model = crystalInputBuilder.buildInputModel((CMLMolecule) cml.getRootElement());
-			} catch (Exception ex) {
-				System.out.println("Problem!: "+ex.getMessage());
+		}
+	}
+
+	private static void convertToCMLLite(File dataDir) {
+		File[] files = dataDir.listFiles();
+		if (files != null) {
+			for (File file : files) {
+				String filename = file.getName();
+				if (filename.endsWith(".xml")) {
+					try {
+						CML2CMLLiteConverter cmlLiteConverter = new CML2CMLLiteConverter();
+						Element rootElement = new CMLBuilder().build(file).getRootElement();
+						rootElement = cmlLiteConverter.convertToXML(rootElement);
+						FileOutputStream fos = new FileOutputStream(filename+".cml");
+						CMLUtil.debug(rootElement, fos, 1);
+					} catch (Exception e) {
+						throw new RuntimeException("cmllite conversion", e);
+					}
+				}
 			}
-			FreeMarkerWriter writer = new FreeMarkerWriter();
-			StringWriter sw = new StringWriter();
-			writer.processTemplate("gauinput.ftl", model, sw);
-			System.out.println(sw);
 		}
-
 	}
 
 }

src/main/resources/org/xmlcml/cml/converters/freemarker/simple.ftl

 // not finalised...
 %NProcShared={NProcShared}
 %Mem={Mem}MW
+        uB971/          6-311       +G                              (d,p)
 #p ${params.qm.method}/{Basis}<#if Diffuse??>${Diffuse}</#if><#if Polarization??>(${Polarization})
 </#if><#if param_converge??>opt=(${param_converge}, NewEstmFC, MaxCyc = ${MaxCyc})
 </#if><#if cmd_freq??>freq GFInput </#if><#if output_pop??>Population=${output_pop} </#if><#if
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.