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

📄 cml23fragmentstest.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(2, mol.getAtomCount());        assertNull(mol.getAtom(0).getPoint3d());        assertNull(mol.getAtom(1).getPoint3d());        assertNotNull(mol.getAtom(0).getFractionalPoint3d());        assertNotNull(mol.getAtom(1).getFractionalPoint3d());    }        public void testMissing2DCoordinates() throws Exception {        String cmlString =           "<molecule id='m1'><atomArray><atom id='a1' xy2='0.0 0.1'/><atom id='a2'/><atom id='a3' xy2='0.1 0.0'/></atomArray></molecule>";                  IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(3, mol.getAtomCount());        IAtom atom1 = mol.getAtom(0);        IAtom atom2 = mol.getAtom(1);        IAtom atom3 = mol.getAtom(2);                assertNotNull(atom1.getPoint2d());        assertNull   (atom2.getPoint2d());        assertNotNull(atom3.getPoint2d());    }    public void testMissing3DCoordinates() throws Exception {        String cmlString =           "<molecule id='m1'><atomArray><atom id='a1' xyz3='0.0 0.1 0.2'/><atom id='a2'/><atom id='a3' xyz3='0.1 0.0 0.2'/></atomArray></molecule>";                  IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals(3, mol.getAtomCount());        IAtom atom1 = mol.getAtom(0);        IAtom atom2 = mol.getAtom(1);        IAtom atom3 = mol.getAtom(2);                assertNotNull(atom1.getPoint3d());        assertNull   (atom2.getPoint3d());        assertNotNull(atom3.getPoint3d());    }        public void testMoleculeId() throws Exception {        String cmlString = "<molecule id='m1'><atomArray><atom id='a1'/></atomArray></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);        assertEquals("m1", mol.getID());    }        public void testName() throws Exception {        String cmlString = "<molecule id='m1'><name>acetic acid</name><atomArray atomID='a1 a2 a3'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals("acetic acid", mol.getProperty(CDKConstants.TITLE));    }        public void testInChI() throws Exception {        String cmlString = "<molecule id='m1'><identifier convention='iupac:inchi' value='InChI=1/CH2O2/c2-1-3/h1H,(H,2,3)'/><atomArray atomID='a1 a2 a3'/></molecule>";                IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertEquals("InChI=1/CH2O2/c2-1-3/h1H,(H,2,3)", mol.getProperty(CDKConstants.INCHI));    }        public void testDictRef() throws Exception {    	String cmlString = "<molecule id=\"alanine\" dictRef=\"pdb:aminoAcid\"><name>alanine</name><name dictRef=\"pdb:residueName\">Ala</name><name dictRef=\"pdb:oneLetterCode\">A</name><scalar dictRef=\"pdb:id\">3</scalar><atomArray><atom id=\"a1\" elementType=\"C\" x2=\"265.0\" y2=\"989.0\"/><atom id=\"a2\" elementType=\"N\" x2=\"234.0\" y2=\"972.0\" dictRef=\"pdb:nTerminus\"/><atom id=\"a3\" elementType=\"C\" x2=\"265.0\" y2=\"1025.0\"/><atom id=\"a4\" elementType=\"C\" x2=\"296.0\" y2=\"971.0\" dictRef=\"pdb:cTerminus\"/><atom id=\"a5\" elementType=\"O\" x2=\"296.0\" y2=\"935.0\"/><atom id=\"a6\" elementType=\"O\" x2=\"327.0\" y2=\"988.0\"/></atomArray><bondArray><bond id=\"b1\" atomRefs2=\"a2 a1\" order=\"S\"/><bond id=\"b2\" atomRefs2=\"a1 a3\" order=\"S\"/><bond id=\"b3\" atomRefs2=\"a1 a4\" order=\"S\"/><bond id=\"b4\" atomRefs2=\"a4 a5\" order=\"D\"/><bond id=\"b5\" atomRefs2=\"a4 a6\" order=\"S\"/></bondArray></molecule>";    	    	IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                Enumeration props = mol.getProperties().keys();        boolean foundDictRefs = false;		while (props.hasMoreElements()) {			Object next = props.nextElement();			if (next instanceof DictRef) foundDictRefs = true;		}		assertTrue(foundDictRefs);    }        public void testQSAROutput() throws Exception {    	String specificationReference = "qsar:weight";    	String implementationTitle = "org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor";    	String implementationIdentifier = "$Id: CML23FragmentsTest.java 8301 2007-05-05 12:00:36 +0000 (Sa, 05 Mai 2007) egonw $";    	String implementationVendor = "The Chemistry Development Kit";    	    	String cmlString = "<molecule xmlns=\"http://www.xml-cml.org/schema\"><atomArray><atom id=\"a5256233\" " +    	    "elementType=\"C\" formalCharge=\"0\" hydrogenCount=\"0\" /><atom id=\"a26250401\" elementType=\"C\" " +    	    "formalCharge=\"0\" hydrogenCount=\"0\" /><atom id=\"a16821027\" elementType=\"C\" formalCharge=\"0\" " +    	    "hydrogenCount=\"0\" /><atom id=\"a14923925\" elementType=\"C\" formalCharge=\"0\" hydrogenCount=\"0\" />" +    	    "<atom id=\"a7043360\" elementType=\"C\" formalCharge=\"0\" hydrogenCount=\"0\" /><atom id=\"a31278839\" " +    	    "elementType=\"C\" formalCharge=\"0\" hydrogenCount=\"0\" /></atomArray><bondArray><bond id=\"b6175092\" " +    	    "atomRefs2=\"a5256233 a26250401\" order=\"S\" /><bond id=\"b914691\" atomRefs2=\"a26250401 a16821027\" " +    	    "order=\"D\" /><bond id=\"b5298332\" atomRefs2=\"a16821027 a14923925\" order=\"S\" /><bond id=\"b29167060\" " +    	    "atomRefs2=\"a14923925 a7043360\" order=\"D\" /><bond id=\"b14093690\" atomRefs2=\"a7043360 a31278839\" " +    	    "order=\"S\" /><bond id=\"b11924794\" atomRefs2=\"a31278839 a5256233\" order=\"D\" /></bondArray>" +    	    "<propertyList><property xmlns:qsar=\"http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/\" " +    	    "convention=\"qsar:DescriptorValue\"><metadataList><metadata dictRef=\"qsar:specificationReference\" " +    	    "content=\"" + specificationReference + "\" /><metadata dictRef=\"qsar:implementationTitle\" content=\"" +    	    implementationTitle + "\" /><metadata dictRef=\"qsar:implementationIdentifier\" " +    	    "content=\"" + implementationIdentifier + "\" /><metadata dictRef=\"" +    	    "qsar:implementationVendor\" content=\"" + implementationVendor + "\" /><metadataList title=\"qsar:" +    	    "descriptorParameters\"><metadata title=\"elementSymbol\" content=\"*\" /></metadataList></metadataList>" +    	    "<scalar dataType=\"xsd:double\" dictRef=\"qsar:weight\">72.0</scalar></property></propertyList></molecule>";    	IChemFile chemFile = parseCMLString(cmlString);        IMolecule mol = checkForSingleMoleculeFile(chemFile);                assertNotNull(mol);        assertEquals(1, mol.getProperties().size());        Object key = mol.getProperties().keySet().toArray()[0];        assertNotNull(key);        assertTrue(key instanceof DescriptorSpecification);        DescriptorSpecification spec = (DescriptorSpecification)key;        assertEquals(specificationReference, spec.getSpecificationReference());        assertEquals(implementationTitle, spec.getImplementationTitle());        assertEquals(implementationIdentifier, spec.getImplementationIdentifier());        assertEquals(implementationVendor, spec.getImplementationVendor());                assertNotNull(mol.getProperty(key));        assertTrue(mol.getProperty(key) instanceof DescriptorValue);        DescriptorValue value = (DescriptorValue)mol.getProperty(key);        IDescriptorResult result = value.getValue();        assertNotNull(result);        assertTrue(result instanceof DoubleResult);        assertEquals(72.0, ((DoubleResult)result).doubleValue(), 0.001);    }        private IChemFile parseCMLString(String cmlString) throws Exception {        IChemFile chemFile = null;        CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes()));        chemFile = (IChemFile)reader.read(new org.openscience.cdk.ChemFile());        return chemFile;    }    /**     * Tests wether the file is indeed a single molecule file     */    private IMolecule checkForSingleMoleculeFile(IChemFile chemFile) {        return checkForXMoleculeFile(chemFile, 1);    }        private IMolecule checkForXMoleculeFile(IChemFile chemFile, int numberOfMolecules) {        assertNotNull(chemFile);                assertEquals(chemFile.getChemSequenceCount(), 1);        org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);        assertNotNull(seq);                assertEquals(seq.getChemModelCount(), 1);        org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);        assertNotNull(model);                org.openscience.cdk.interfaces.IMoleculeSet moleculeSet = model.getMoleculeSet();        assertNotNull(moleculeSet);                assertEquals(moleculeSet.getMoleculeCount(), numberOfMolecules);        IMolecule mol = null;        for (int i=0; i<numberOfMolecules; i++) {            mol = moleculeSet.getMolecule(i);            assertNotNull(mol);        }        return mol;    }//    private ICrystal checkForCrystalFile(IChemFile chemFile) {//        assertNotNull(chemFile);//        //        assertEquals(chemFile.getChemSequenceCount(), 1);//        org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);//        assertNotNull(seq);//        //        assertEquals(seq.getChemModelCount(), 1);//        org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);//        assertNotNull(model);//        //        org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal();//        assertNotNull(crystal);//        //        return crystal;//    }        public void testReaction() throws Exception {        String cmlString = "<reaction>"+        "<reactantList><reactant><molecule id='react'/></reactant></reactantList>"+		"<productList><product><molecule id='product'/></product></productList>"+        "<substanceList><substance><molecule id='water'/></substance></substanceList>"+        "</reaction>";                IChemFile chemFile = parseCMLString(cmlString);        IReaction reaction = checkForSingleReactionFile(chemFile);        assertEquals(1, reaction.getReactantCount());        assertEquals(1, reaction.getProductCount());        assertEquals(1, reaction.getAgents().getMoleculeCount());        assertEquals("react", reaction.getReactants().getMolecule(0).getID());        assertEquals("product", reaction.getProducts().getMolecule(0).getID());        assertEquals("water", reaction.getAgents().getMolecule(0).getID());    }        /**     * Tests wether the file is indeed a single reaction file     */    private IReaction checkForSingleReactionFile(IChemFile chemFile) {        return checkForXReactionFile(chemFile, 1);    }        private IReaction checkForXReactionFile(IChemFile chemFile, int numberOfReactions) {        assertNotNull(chemFile);                assertEquals(chemFile.getChemSequenceCount(), 1);        org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);        assertNotNull(seq);                assertEquals(seq.getChemModelCount(), 1);        org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);        assertNotNull(model);                IReactionSet reactionSet = model.getReactionSet();        assertNotNull(reactionSet);                assertEquals(reactionSet.getReactionCount(), numberOfReactions);        IReaction reaction = null;        for (int i=0; i<numberOfReactions; i++) {            reaction = reactionSet.getReaction(i);            assertNotNull(reaction);        }        return reaction;    }}

⌨️ 快捷键说明

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