public static List<String> getAllIDs(IChemModel chemModel) { ArrayList<String> list = new ArrayList<String>(); if (chemModel.getID() != null) list.add(chemModel.getID()); ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { list.addAll(AtomContainerManipulator.getAllIDs(crystal)); } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { list.addAll(MoleculeSetManipulator.getAllIDs(moleculeSet)); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { list.addAll(ReactionSetManipulator.getAllIDs(reactionSet)); } return list; } }
private void writeChemSequence(IChemSequence cs) throws UnsupportedChemObjectException { int count = cs.getChemModelCount(); for (int i = 0; i < count; i++) { writeln("frame: " + (i + 1)); writeCrystal(cs.getChemModel(i).getCrystal()); } }
/** * Sets the AtomProperties of all Atoms inside an IChemModel. * * @param chemModel The IChemModel object. * @param propKey The key of the property. * @param propVal The value of the property. */ public static void setAtomProperties(IChemModel chemModel, Object propKey, Object propVal) { if (chemModel.getMoleculeSet() != null) { MoleculeSetManipulator.setAtomProperties(chemModel.getMoleculeSet(), propKey, propVal); } if (chemModel.getReactionSet() != null) { ReactionSetManipulator.setAtomProperties(chemModel.getReactionSet(), propKey, propVal); } if (chemModel.getCrystal() != null) { AtomContainerManipulator.setAtomProperties(chemModel.getCrystal(), propKey, propVal); } }
@Test public void testClone_Crystal() throws Exception { IChemModel model = (IChemModel) newChemObject(); IChemModel clone = (IChemModel) model.clone(); Assert.assertNull(clone.getCrystal()); model.setCrystal(model.getBuilder().newInstance(ICrystal.class)); clone = (IChemModel) model.clone(); Assert.assertNotNull(clone.getCrystal()); Assert.assertNotSame(model.getCrystal(), clone.getCrystal()); }
/** * Get the total number of bonds inside an IChemModel. * * @param chemModel The IChemModel object. * @return The number of Bond object inside. */ public static int getBondCount(IChemModel chemModel) { int count = 0; ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { count += crystal.getBondCount(); } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { count += MoleculeSetManipulator.getBondCount(moleculeSet); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { count += ReactionSetManipulator.getBondCount(reactionSet); } return count; }
/** * Get the total number of atoms inside an IChemModel. * * @param chemModel The IChemModel object. * @return The number of Atom object inside. */ public static int getAtomCount(IChemModel chemModel) { int count = 0; ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { count += crystal.getAtomCount(); } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { count += MoleculeSetManipulator.getAtomCount(moleculeSet); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { count += ReactionSetManipulator.getAtomCount(reactionSet); } return count; }
private CMLList cdkChemModelToCMLList(IChemModel model, boolean setIDs) { CMLList cmlList = new CMLList(); cmlList.setConvention("cdk:model"); if (useCMLIDs && setIDs) { IDCreator.createIDs(model); } if (model.getID() != null && !model.getID().equals("")) cmlList.setId(model.getID()); if (model.getCrystal() != null) { cmlList.appendChild(cdkCrystalToCMLMolecule(model.getCrystal(), false)); } if (model.getReactionSet() != null) { cmlList.appendChild(cdkReactionSetToCMLReactionList(model.getReactionSet(), false)); } if (model.getMoleculeSet() != null) { cmlList.appendChild(cdkAtomContainerSetToCMLList(model.getMoleculeSet(), false)); } return cmlList; }
/** * Remove an Atom and the connected ElectronContainers from all AtomContainers * inside an IChemModel. * * @param chemModel The IChemModel object. * @param atom The Atom object to remove. */ public static void removeAtomAndConnectedElectronContainers(IChemModel chemModel, IAtom atom) { ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { if (crystal.contains(atom)) { crystal.removeAtom(atom); } return; } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(moleculeSet, atom); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { ReactionSetManipulator.removeAtomAndConnectedElectronContainers(reactionSet, atom); } }
private CMLList cdkChemModelToCMLList(IChemModel model, boolean setIDs) { CMLList cmlList = new CMLList(); cmlList.setConvention("cdk:model"); if (useCMLIDs && setIDs) { IDCreator.createIDs(model); } if (model.getID() != null && !model.getID().equals("")) cmlList.setId(model.getID()); if (model.getCrystal() != null) { cmlList.appendChild(cdkCrystalToCMLMolecule(model.getCrystal(), false)); } if (model.getReactionSet() != null) { cmlList.appendChild(cdkReactionSetToCMLReactionList(model.getReactionSet(), false)); } if (model.getMoleculeSet() != null) { cmlList.appendChild(cdkAtomContainerSetToCMLList(model.getMoleculeSet(), false)); } return cmlList; }
@Test public void cod1100784AtomCount() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Assert.assertEquals(72, crystal.getAtomCount()); cifReader.close(); }
@Test() public void cod1100784CellLengths() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Assert.assertTrue( java.lang.Math.abs(crystal.getA().length() - 10.9754) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getB().length() - 11.4045) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getC().length() - 12.9314) < 1E-5 ); cifReader.close(); }
@Test public void testSetCrystal_ICrystal() { IChemModel chemModel = (IChemModel) newChemObject(); ICrystal crystal = chemModel.getBuilder().newInstance(ICrystal.class); chemModel.setCrystal(crystal); Assert.assertEquals(crystal, chemModel.getCrystal()); }
@Override public ValidationReport validateChemModel(IChemModel subject) { logger.info("Validating org.openscience.cdk.ChemModel"); ValidationReport report = new ValidationReport(); // apply validators for (IValidator test : validators.values()) { report.addReport(test.validateChemModel(subject)); } // traverse into super class report.addReport(validateChemObject(subject)); // traverse into hierarchy ICrystal crystal = subject.getCrystal(); if (crystal != null) { report.addReport(validateCrystal(crystal)); } IReactionSet reactionSet = subject.getReactionSet(); if (reactionSet != null) { report.addReport(validateReactionSet(reactionSet)); } IAtomContainerSet moleculeSet = subject.getMoleculeSet(); if (moleculeSet != null) { report.addReport(validateMoleculeSet(moleculeSet)); } return report; }
/** * Ensure a CIF file from the crystallography open database can be read. * Example input <a href="http://www.crystallography.net/1100784.cif">1100784</a>. */ @Test public void cod1100784() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); // try { IChemFile chemFile = cifReader.read(new ChemFile()); Assert.assertThat(chemFile.getChemSequenceCount(), is(1)); Assert.assertThat(chemFile.getChemSequence(0).getChemModelCount(), is(1)); Assert.assertNotNull(chemFile.getChemSequence(0).getChemModel(0).getCrystal()); // } finally { cifReader.close(); // } }
@Test() public void cod1100784CellAngles() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Vector3d a = crystal.getA(); Vector3d b = crystal.getB(); Vector3d c = crystal.getC(); double alpha = java.lang.Math.acos(b.dot(c)/(b.length()*c.length()))*180/java.lang.Math.PI; double beta = java.lang.Math.acos(c.dot(a)/(c.length()*a.length()))*180/java.lang.Math.PI; double gamma = java.lang.Math.acos(a.dot(b)/(a.length()*b.length()))*180/java.lang.Math.PI; Assert.assertTrue( java.lang.Math.abs(alpha - 109.1080) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(beta - 98.4090) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(gamma - 102.7470) < 1E-5 ); cifReader.close(); }
@Test public void testReading() throws Exception { String filename = "data/vasp/LiMoS2_optimisation_ISIF3.vasp"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); VASPReader reader = new VASPReader(ins); ChemFile chemFile = (ChemFile) reader.read(new ChemFile()); Assert.assertNotNull(chemFile); org.openscience.cdk.interfaces.IChemSequence sequence = chemFile.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(6, sequence.getChemModelCount()); org.openscience.cdk.interfaces.IChemModel model = sequence.getChemModel(0); Assert.assertNotNull(model); org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal(); Assert.assertNotNull(crystal); Assert.assertEquals(16, crystal.getAtomCount()); org.openscience.cdk.interfaces.IAtom atom = crystal.getAtom(0); Assert.assertNotNull(atom); Assert.assertNotNull(atom.getFractionalPoint3d()); } }
@Test public void testTwoAceticAcid() throws Exception { String filename = "data/pmp/two_aceticacid.pmp"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); PMPReader reader = new PMPReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(2, seq.getChemModelCount()); IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); ICrystal crystal = model.getCrystal(); Assert.assertNotNull(crystal); Assert.assertEquals(32, crystal.getAtomCount()); Assert.assertEquals(28, crystal.getBondCount()); model = seq.getChemModel(1); Assert.assertNotNull(model); crystal = model.getCrystal(); Assert.assertNotNull(crystal); Assert.assertEquals(32, crystal.getAtomCount()); Assert.assertEquals(28, crystal.getBondCount()); } }
private org.openscience.cdk.interfaces.ICrystal checkForCrystalFile(IChemFile chemFile) { Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal(); if (crystal != null) return crystal; // null crystal, try and find it in the set IAtomContainerSet set = model.getMoleculeSet(); Assert.assertNotNull(set); for (IAtomContainer container : set.atomContainers()) { if (container instanceof ICrystal) { crystal = (ICrystal) container; return crystal; } } Assert.fail("no crystal could be found in the ChemModel"); return crystal; }
private org.openscience.cdk.interfaces.ICrystal checkForCrystalFile(IChemFile chemFile) { Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal(); if (crystal != null) return crystal; // null crystal, try and find it in the set IAtomContainerSet set = model.getMoleculeSet(); Assert.assertNotNull(set); for (IAtomContainer container : set.atomContainers()) { if (container instanceof ICrystal) { crystal = (ICrystal) container; return crystal; } } Assert.fail("no crystal could be found in the ChemModel"); return crystal; }
@Test public void testAceticAcid() throws Exception { String filename = "data/pmp/aceticacid.pmp"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); PMPReader reader = new PMPReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(1, seq.getChemModelCount()); IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); ICrystal crystal = model.getCrystal(); Assert.assertNotNull(crystal); Assert.assertEquals(32, crystal.getAtomCount()); Assert.assertEquals(28, crystal.getBondCount()); Assert.assertEquals("O", crystal.getAtom(6).getSymbol()); Assert.assertEquals(1.4921997, crystal.getAtom(6).getPoint3d().x, 0.00001); Assert.assertEquals("O", crystal.getAtom(7).getSymbol()); Assert.assertEquals(1.4922556, crystal.getAtom(7).getPoint3d().x, 0.00001); }