📄 cmlcoremodule.java
字号:
/* $Revision: 8301 $ $Author: egonw $ $Date: 2007-05-05 14:00:36 +0200 (Sat, 05 May 2007) $ * * Copyright (C) 1997-2007 Egon Willighagen <egonw@users.sf.net> * * Contact: cdk-devel@lists.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * All we ask is that proper credit is given for our work, which includes * - but is not limited to - adding the above copyright notice to the beginning * of your source code files, and to any copyright notice that you may distribute * with programs based on this work. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * */package org.openscience.cdk.io.cml;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import javax.vecmath.Point2d;import javax.vecmath.Point3d;import javax.vecmath.Vector3d;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.config.IsotopeFactory;import org.openscience.cdk.dict.DictRef;import org.openscience.cdk.geometry.CrystalGeometryTools;import org.openscience.cdk.interfaces.IAtom;import org.openscience.cdk.interfaces.IAtomContainer;import org.openscience.cdk.interfaces.IBond;import org.openscience.cdk.interfaces.IChemFile;import org.openscience.cdk.interfaces.IChemModel;import org.openscience.cdk.interfaces.IChemSequence;import org.openscience.cdk.interfaces.ICrystal;import org.openscience.cdk.interfaces.IMolecule;import org.openscience.cdk.interfaces.IMoleculeSet;import org.openscience.cdk.interfaces.IMonomer;import org.openscience.cdk.interfaces.IPseudoAtom;import org.openscience.cdk.interfaces.IReaction;import org.openscience.cdk.interfaces.IReactionSet;import org.openscience.cdk.interfaces.IStrand;import org.openscience.cdk.tools.LoggingTool;import org.xml.sax.Attributes;/** * Core CML 1.x and 2.0 elements are parsed by this class. * * <p>Please file a bug report if this parser fails to parse * a certain element or attribute value in a valid CML document. * * @cdk.module io * * @author Egon Willighagen <egonw@sci.kun.nl> **/public class CMLCoreModule implements ICMLModule { protected org.openscience.cdk.tools.LoggingTool logger; protected final String SYSTEMID = "CML-1999-05-15";// protected IChemicalDocumentObject cdo; // data model to store things into protected IChemFile currentChemFile; protected IAtomContainer currentMolecule; protected IMoleculeSet currentMoleculeSet; protected IChemModel currentChemModel; protected IChemSequence currentChemSequence; protected IReactionSet currentReactionSet; protected IReaction currentReaction; protected IAtom currentAtom; protected IBond currentBond; protected IStrand currentStrand; protected IMonomer currentMonomer; protected Map atomEnumeration; // helper fields protected int atomCounter; protected List elsym; protected List eltitles; protected List elid; protected List formalCharges; protected List partialCharges; protected List isotope; protected List x3; protected List y3; protected List z3; protected List x2; protected List y2; protected List xfract; protected List yfract; protected List zfract; protected List hCounts; protected List atomParities; protected List atomDictRefs; protected List spinMultiplicities; protected List occupancies; protected int bondCounter; protected List bondid; protected List bondARef1; protected List bondARef2; protected List order; protected List bondStereo; protected List bondDictRefs; protected List bondElid; protected List bondAromaticity; protected boolean stereoGiven; protected String inchi; protected int curRef; protected int CurrentElement; protected String BUILTIN; protected String DICTREF; protected String elementTitle; protected String currentChars; protected double[] unitcellparams; protected int crystalScalar; // private Vector3d aAxis;// private Vector3d bAxis;// private Vector3d cAxis; boolean cartesianAxesSet = false; public CMLCoreModule(IChemFile chemFile) { logger = new LoggingTool(this); this.currentChemFile = chemFile; } public CMLCoreModule(ICMLModule conv) { logger = new LoggingTool(this); inherit(conv); } public void inherit(ICMLModule convention) { if (convention instanceof CMLCoreModule) { CMLCoreModule conv = (CMLCoreModule)convention; // copy the data model this.currentChemFile = conv.currentChemFile; this.currentMolecule = conv.currentMolecule; this.currentMoleculeSet = conv.currentMoleculeSet; this.currentChemModel = conv.currentChemModel; this.currentChemSequence = conv.currentChemSequence; this.currentReactionSet = conv.currentReactionSet; this.currentReaction = conv.currentReaction; this.currentAtom = conv.currentAtom; this.currentStrand = conv.currentStrand; this.currentMonomer = conv.currentMonomer; this.atomEnumeration = conv.atomEnumeration; // copy the intermediate fields this.logger = conv.logger; this.BUILTIN = conv.BUILTIN; this.atomCounter = conv.atomCounter; this.elsym = conv.elsym; this.eltitles = conv.eltitles; this.elid = conv.elid; this.formalCharges = conv.formalCharges; this.partialCharges = conv.partialCharges; this.isotope = conv.isotope; this.x3 = conv.x3; this.y3 = conv.y3; this.z3 = conv.z3; this.x2 = conv.x2; this.y2 = conv.y2; this.xfract = conv.xfract; this.yfract = conv.yfract; this.zfract = conv.zfract; this.hCounts = conv.hCounts; this.atomParities = conv.atomParities; this.atomDictRefs = conv.atomDictRefs; this.spinMultiplicities = conv.spinMultiplicities; this.occupancies = conv.occupancies; this.bondCounter = conv.bondCounter; this.bondid = conv.bondid; this.bondARef1 = conv.bondARef1; this.bondARef2 = conv.bondARef2; this.order = conv.order; this.bondStereo = conv.bondStereo; this.bondDictRefs = conv.bondDictRefs; this.bondAromaticity = conv.bondAromaticity; this.curRef = conv.curRef; this.unitcellparams = conv.unitcellparams; this.inchi = conv.inchi; } else { logger.warn("Cannot inherit information from module: ", convention.getClass().getName()); } } public IChemFile returnChemFile() { return currentChemFile; } /** * Clean all data about parsed data. */ protected void newMolecule() { newMoleculeData(); newAtomData(); newBondData(); newCrystalData(); } /** * Clean all data about the molecule itself. */ protected void newMoleculeData() { this.inchi = null; } /** * Clean all data about read atoms. */ protected void newAtomData() { atomCounter = 0; elsym = new ArrayList(); elid = new ArrayList(); eltitles = new ArrayList(); formalCharges = new ArrayList(); partialCharges = new ArrayList(); isotope = new ArrayList(); x3 = new ArrayList(); y3 = new ArrayList(); z3 = new ArrayList(); x2 = new ArrayList(); y2 = new ArrayList(); xfract = new ArrayList(); yfract = new ArrayList(); zfract = new ArrayList(); hCounts = new ArrayList(); atomParities = new ArrayList(); atomDictRefs = new ArrayList(); spinMultiplicities = new ArrayList(); occupancies = new ArrayList(); } /** * Clean all data about read bonds. */ protected void newBondData() { bondCounter = 0; bondid = new ArrayList(); bondARef1 = new ArrayList(); bondARef2 = new ArrayList(); order = new ArrayList(); bondStereo = new ArrayList(); bondDictRefs = new ArrayList(); bondElid = new ArrayList(); bondAromaticity = new ArrayList(); } /** * Clean all data about read bonds. */ protected void newCrystalData() { unitcellparams = new double[6]; cartesianAxesSet = false; crystalScalar = 0;// aAxis = new Vector3d();// bAxis = new Vector3d();// cAxis = new Vector3d(); } public void startDocument() { logger.info("Start XML Doc"); // cdo.startDocument(); currentChemSequence = currentChemFile.getBuilder().newChemSequence(); currentChemModel = currentChemFile.getBuilder().newChemModel(); currentMoleculeSet = currentChemFile.getBuilder().newMoleculeSet(); currentMolecule = currentChemFile.getBuilder().newMolecule(); atomEnumeration = new HashMap(); newMolecule(); BUILTIN = ""; curRef = 0; } public void endDocument() {// cdo.endDocument(); if (currentReactionSet != null && currentReactionSet.getReactionCount() == 0 && currentReaction != null) { logger.debug("Adding reaction to ReactionSet"); currentReactionSet.addReaction(currentReaction); } if (currentReactionSet != null && currentChemModel.getReactionSet() == null) { logger.debug("Adding SOR to ChemModel"); currentChemModel.setReactionSet(currentReactionSet); } if (currentMoleculeSet != null && currentMoleculeSet.getMoleculeCount() != 0) { logger.debug("Adding reaction to MoleculeSet"); currentChemModel.setMoleculeSet(currentMoleculeSet); } if (currentChemSequence.getChemModelCount() == 0) { logger.debug("Adding ChemModel to ChemSequence"); currentChemSequence.addChemModel(currentChemModel); } if (currentChemFile.getChemSequenceCount() == 0) { // assume there is one non-animation ChemSequence// addChemSequence(currentChemSequence); currentChemFile.addChemSequence(currentChemSequence); } logger.info("End XML Doc"); } public void startElement(CMLStack xpath, String uri, String local, String raw, Attributes atts) { String name = local; logger.debug("StartElement"); currentChars = ""; BUILTIN = ""; DICTREF = ""; for (int i=0; i<atts.getLength(); i++) { String qname = atts.getQName(i); if (qname.equals("builtin")) { BUILTIN = atts.getValue(i); logger.debug(name, "->BUILTIN found: ", atts.getValue(i)); } else if (qname.equals("dictRef")) { DICTREF = atts.getValue(i); logger.debug(name, "->DICTREF found: ", atts.getValue(i)); } else if (qname.equals("title")) { elementTitle = atts.getValue(i); logger.debug(name, "->TITLE found: ", atts.getValue(i)); } else { logger.debug("Qname: ", qname); } } if ("atom".equals(name)) { atomCounter++; for (int i = 0; i < atts.getLength(); i++) { String att = atts.getQName(i); String value = atts.getValue(i); if (att.equals("id")) { // this is supported in CML 1.x elid.add(value); } // this is supported in CML 2.0 else if (att.equals("elementType")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -