⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdbconvention.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Revision: 7981 $ $Author: egonw $ $Date: 2007-02-20 18:05:37 +0100 (Tue, 20 Feb 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.StringTokenizer;import javax.vecmath.Point2d;import javax.vecmath.Point3d;import org.openscience.cdk.CDKConstants;import org.openscience.cdk.config.IsotopeFactory;import org.openscience.cdk.interfaces.IChemFile;import org.openscience.cdk.interfaces.ICrystal;import org.openscience.cdk.interfaces.IMolecule;import org.openscience.cdk.interfaces.IPDBAtom;import org.openscience.cdk.interfaces.IPDBMonomer;import org.openscience.cdk.interfaces.IPDBPolymer;import org.openscience.cdk.interfaces.IPseudoAtom;import org.xml.sax.Attributes;/** * Implements the PDB convention used by PDB2CML. * * <p>This is a lousy implementation, though. Problems that will arise: * <ul> *   <li>when this new convention is adopted in the root element no *     currentFrame was set. This is done when <list sequence=""> is found *   <li>multiple sequences are not yet supported *   <li>the frame is now added when the doc is ended, which will result in problems *     but work for one sequence files made by PDB2CML v.?? * <ul> * * <p>What is does: * <ul> *   <li>work for now *   <li>give an idea on the API of the plugable CML import filter *     (a real one will be made) *   <li>read CML files generated with Steve Zara's PDB 2 CML converter *     (of which version 1999 produces invalid CML 1.0) * </ul> * * @cdk.module io * * @author Egon Willighagen <egonw@sci.kun.nl> */public class PDBConvention extends CMLCoreModule {    private boolean connectionTable;    private boolean isELSYM;    private boolean isBond;    private String connect_root;	private boolean hasScalar;	private String idValue = "";	private ArrayList altLocV;	private ArrayList chainIDV;	private ArrayList hetAtomV;	private ArrayList iCodeV;	private ArrayList nameV;	private ArrayList oxtV;	private ArrayList recordV;	private ArrayList resNameV;	private ArrayList resSeqV;	private ArrayList segIDV;	private ArrayList serialV;	private ArrayList tempFactorV;	    public PDBConvention(IChemFile chemFile) {        super(chemFile);    }        public PDBConvention(ICMLModule conv) {        super(conv);    }    public void endDocument() {        storeData();        super.endDocument();    }        public void startElement(CMLStack xpath, String uri, String local, String raw,                               Attributes atts) {        String name = raw;        isELSYM = false;        if ("molecule".equals(name)) {        	            for (int j = 0; j < atts.getLength(); j++) {            	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 (atts.getQName(j).equals("convention") && atts.getValue(j).equals("PDB")) {//                    cdo.startObject("PDBPolymer");                	currentStrand = currentChemFile.getBuilder().newStrand();                	currentStrand.setStrandName("A");                    currentMolecule = currentChemFile.getBuilder().newPDBPolymer();                }else if (atts.getQName(j).equals("dictRef") && atts.getValue(j).equals("pdb:sequence")) {                                        newSequence();                    BUILTIN = "";                    for (int i = 0; i < atts.getLength(); i++) {                        if (atts.getQName(i).equals("id")) {//                            cdo.setObjectProperty("Molecule", "id", atts.getValue(i));                            currentMolecule.setID(atts.getValue(i));                        } else if (atts.getQName(i).equals("dictRef")) {//                        	cdo.setObjectProperty("Molecule", "dictRef", atts.getValue(i));                        	// FIXME: has no equivalent in ChemFileCDO                        }                    }                	                } else if (atts.getQName(j).equals("title") &&                          atts.getValue(j).equals("connections")) {                    // assume that Atom's have been read                    logger.debug("Assuming that Atom's have been read: storing them");                    super.storeAtomData();                    connectionTable = true;                    logger.debug("Start Connection Table");                } else if (atts.getQName(j).equals("title") &&                          atts.getValue(j).equals("connect")) {                    logger.debug("New connection");                    isBond = true;                } else if (atts.getQName(j).equals("id") && isBond) {                    connect_root = atts.getValue(j);                }                // ignore other list items at this moment            }        }else if ("scalar".equals(name)) {        	hasScalar = true;        	for (int i = 0; i < atts.getLength(); i++) {                if(atts.getQName(i).equals("dictRef"))                	idValue = atts.getValue(i);        	}        }else if ("label".equals(name)) {        	hasScalar = true;        	for (int i = 0; i < atts.getLength(); i++) {                if(atts.getQName(i).equals("dictRef"))                	idValue = atts.getValue(i);        	}        }else if ("atom".equals(name)) {        	super.startElement(xpath, uri, local, raw, atts);        }    }        public void newSequence(){    	altLocV = new ArrayList();    	chainIDV = new ArrayList();    	hetAtomV = new ArrayList();    	iCodeV = new ArrayList();    	nameV = new ArrayList();    	oxtV = new ArrayList();    	recordV = new ArrayList();    	resNameV = new ArrayList();    	resSeqV = new ArrayList();    	segIDV = new ArrayList();    	serialV = new ArrayList();    	tempFactorV = new ArrayList();    	    }    public void endElement(CMLStack xpath, String uri, String local, String raw) {        String name = raw;        // OLD +++++++++++++++++++++++++++++++++++++++++++++        if (name.equals("list") && connectionTable && !isBond) {            logger.debug("End Connection Table");            connectionTable = false;        // OLD +++++++++++++++++++++++++++++++++++++++++++++                 } else if(name.equals("molecule")){        	storeData();            if(xpath.sp == 1){//	        	cdo.endObject("Molecule");            	if (currentMolecule instanceof IMolecule) {                    logger.debug("Adding molecule to set");                    currentMoleculeSet.addMolecule((IMolecule)currentMolecule);                    logger.debug("#mols in set: " + currentMoleculeSet.getMoleculeCount());                } else if (currentMolecule instanceof ICrystal) {                    logger.debug("Adding crystal to chemModel");                    currentChemModel.setCrystal((ICrystal)currentMolecule);                    currentChemSequence.addChemModel(currentChemModel);                }        	}        }        isELSYM = false;        isBond = false;            }    public void characterData(CMLStack xpath, char[] ch, int start, int length) {        String s = new String(ch, start, length).trim();        StringTokenizer st1 = new StringTokenizer(s);        String dictpdb = "";        while (st1.hasMoreElements()) {        	            dictpdb += (String)st1.nextElement();            if(st1.hasMoreElements())            	dictpdb += " ";            else if(idValue.equals("pdb:record"))            	dictpdb += " ";        }        if(idValue.equals("pdb:altLoc"))            altLocV.add(dictpdb);        else if(idValue.equals("pdb:chainID"))        	chainIDV.add(dictpdb);        else if(idValue.equals("pdb:hetAtom"))        	hetAtomV.add(dictpdb);        else if(idValue.equals("pdb:iCode"))        	iCodeV.add(dictpdb);        else if(idValue.equals("pdb:name"))        	nameV.add(dictpdb);        else if(idValue.equals("pdb:oxt"))        	oxtV.add(dictpdb);        else if(idValue.equals("pdb:record"))        	recordV.add(dictpdb);        else if(idValue.equals("pdb:resName"))        	resNameV.add(dictpdb);        else if(idValue.equals("pdb:resSeq"))        	resSeqV.add(dictpdb);        else if(idValue.equals("pdb:segID"))        	segIDV.add(dictpdb);        else if(idValue.equals("pdb:serial"))        	serialV.add(dictpdb);        else if(idValue.equals("pdb:tempFactor"))        	tempFactorV.add(dictpdb);                idValue = "";                if (isELSYM) {            elsym.add(s);        } else if (isBond) {            logger.debug("CD (bond): " + s);            if (connect_root.length() > 0) {                StringTokenizer st = new StringTokenizer(s);                while (st.hasMoreElements()) {                    String atom = (String)st.nextElement();                    if (!atom.equals("0")) {                        logger.debug("new bond: " + connect_root + "-" +                                      atom);//                        cdo.startObject("Bond");//                        int atom1 = Integer.parseInt(connect_root) - 1;//                        int atom2 = Integer.parseInt(atom) - 1;//                        cdo.setObjectProperty("Bond", "atom1", //                                (new Integer(atom1)).toString());//                        cdo.setObjectProperty("Bond", "atom2", //                                (new Integer(atom2)).toString());                        currentBond = currentMolecule.getBuilder().newBond(                        	currentMolecule.getAtom(Integer.parseInt(connect_root) - 1),                        	currentMolecule.getAtom(Integer.parseInt(atom) - 1),                        	CDKConstants.BONDORDER_SINGLE                        );                        currentMolecule.addBond(currentBond);                    }                }            }        }     }            protected void storeData() {        if (inchi != null) {//            cdo.setObjectProperty("Molecule", "inchi", inchi);            currentMolecule.setProperty(CDKConstants.INCHI, inchi);        }        storeAtomData();        storeBondData();    }    protected void storeAtomData() {        logger.debug("No atoms: ", atomCounter);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -