Search in sources :

Example 1 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project ambit-mirror by ideaconsult.

the class MoleculeTools method readCMLMolecule.

public static IAtomContainer readCMLMolecule(InputStream in) throws Exception {
    IAtomContainer mol = null;
    CMLReader reader = new CMLReader(in);
    IChemFile obj = null;
    obj = (IChemFile) reader.read(newChemFile(SilentChemObjectBuilder.getInstance()));
    int n = obj.getChemSequenceCount();
    if (n > 1)
        logger.finest("> 1 sequence in a record");
    for (int j = 0; j < n; j++) {
        IChemSequence seq = obj.getChemSequence(j);
        int m = seq.getChemModelCount();
        if (m > 1)
            logger.finest("> 1 model in a record");
        for (int k = 0; k < m; k++) {
            IChemModel mod = seq.getChemModel(k);
            IAtomContainerSet som = mod.getMoleculeSet();
            if (som.getAtomContainerCount() > 1)
                logger.finest("> 1 molecule in a record");
            for (int l = 0; l < som.getAtomContainerCount(); l++) {
                mol = som.getAtomContainer(l);
                return mol;
            }
        }
    }
    reader = null;
    return mol;
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 2 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project ambit-mirror by ideaconsult.

the class CdkJmolAdapter method openBufferedReader.

/* **************************************************************
	 * the file related methods
	 * **************************************************************/
public Object openBufferedReader(String name, BufferedReader bufferedReader) {
    IChemFile chemFile = null;
    try {
        ISimpleChemObjectReader chemObjectReader = null;
        try {
            chemObjectReader = new ReaderFactory().createReader(bufferedReader);
        } catch (IOException ex) {
            return "Jmol: Error determining input format: " + ex;
        }
        if (chemObjectReader == null) {
            return "Jmol: unrecognized input format";
        }
        chemFile = (IChemFile) chemObjectReader.read(new org.openscience.cdk.ChemFile());
    } catch (CDKException ex) {
        return "Error reading input:" + ex;
    }
    if (chemFile == null)
        return "unknown error reading file";
    try {
        AtomTypeFactory factory = AtomTypeFactory.getInstance("pdb_atomtypes.txt", chemFile.getBuilder());
        // IAtomContainer atomContainer = (IAtomContainer)ChemFileManipulator.getAllInOneContainer(chemFile);
        Iterator<IChemSequence> seq = chemFile.chemSequences().iterator();
        while (seq.hasNext()) {
            Iterator<IChemModel> model = seq.next().chemModels().iterator();
            while (model.hasNext()) {
                Iterator<IAtomContainer> c = model.next().getMoleculeSet().atomContainers().iterator();
                while (c.hasNext()) {
                    Iterator<IAtom> it = c.next().atoms().iterator();
                    while (it.hasNext()) {
                        IAtom atom = it.next();
                        try {
                            factory.configure(atom);
                        } catch (CDKException exception) {
                            bcLogger.severe("Could not configure atom: " + atom);
                            bcLogger.log(Level.SEVERE, "  because: " + exception.getMessage(), exception);
                        }
                    }
                }
            }
        }
        return chemFile;
    } catch (Exception x) {
        return "Error configuring atoms input:" + x;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) ReaderFactory(org.openscience.cdk.io.ReaderFactory) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class ChemModelTest method testChemModel.

@Test
public void testChemModel() {
    IChemModel chemModel = new ChemModel();
    Assert.assertNotNull(chemModel);
    Assert.assertTrue(chemModel.isEmpty());
    IAtom atom = new Atom("N");
    IAtomContainer mol = new AtomContainer();
    IAtomContainerSet mset = new AtomContainerSet();
    mol.addAtom(atom);
    mset.addAtomContainer(mol);
    chemModel.setMoleculeSet(mset);
    Assert.assertFalse(chemModel.isEmpty());
    mol.removeAtomOnly(atom);
    Assert.assertFalse(chemModel.isEmpty());
    chemModel.setMoleculeSet(null);
    Assert.assertTrue(chemModel.isEmpty());
    IChemModel model1 = new ChemModel();
    mol.addAtom(atom);
    IReaction react = new Reaction();
    react.addReactant(mol);
    IReactionSet rset = new ReactionSet();
    rset.addReaction(react);
    model1.setReactionSet(rset);
    Assert.assertFalse(model1.isEmpty());
    mol.removeAtomOnly(atom);
    Assert.assertFalse(model1.isEmpty());
    model1.setReactionSet(null);
    Assert.assertTrue(model1.isEmpty());
    IChemModel model2 = new ChemModel();
    mol.addAtom(atom);
    IRingSet ringset = new RingSet();
    ringset.add(mset);
    model2.setRingSet(ringset);
    Assert.assertFalse(model2.isEmpty());
    mol.removeAtomOnly(atom);
    Assert.assertFalse(model2.isEmpty());
    model2.setRingSet(null);
    Assert.assertTrue(model2.isEmpty());
    IChemModel model3 = new ChemModel();
    mol.addAtom(atom);
    ICrystal cry = new Crystal(mol);
    model3.setCrystal(cry);
    Assert.assertFalse(model3.isEmpty());
    mol.removeAtomOnly(atom);
    Assert.assertFalse(model3.isEmpty());
    model3.setCrystal(null);
    Assert.assertTrue(model3.isEmpty());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ICrystal(org.openscience.cdk.interfaces.ICrystal) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) IRingSet(org.openscience.cdk.interfaces.IRingSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IRingSet(org.openscience.cdk.interfaces.IRingSet) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) ICrystal(org.openscience.cdk.interfaces.ICrystal) AbstractChemModelTest(org.openscience.cdk.test.interfaces.AbstractChemModelTest) Test(org.junit.Test)

Example 4 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class DebugChemModelTest method testDebugChemModel.

@Test
public void testDebugChemModel() {
    IChemModel chemModel = new DebugChemModel();
    Assert.assertNotNull(chemModel);
}
Also used : IChemModel(org.openscience.cdk.interfaces.IChemModel) AbstractChemModelTest(org.openscience.cdk.test.interfaces.AbstractChemModelTest) Test(org.junit.Test)

Example 5 with IChemModel

use of org.openscience.cdk.interfaces.IChemModel in project cdk by cdk.

the class ChemModelTest method testStateChanged_ButNotAfterRemoval_AtomContainerSet.

@Override
@Test
public void testStateChanged_ButNotAfterRemoval_AtomContainerSet() {
    ChemObjectListener listener = new ChemObjectListener();
    IChemModel chemObject = (IChemModel) newChemObject();
    chemObject.addListener(listener);
    IAtomContainerSet molSet = chemObject.getBuilder().newInstance(IAtomContainerSet.class);
    chemObject.setMoleculeSet(molSet);
    Assert.assertFalse(listener.getChanged());
    // remove the set from the IChemModel
    chemObject.setMoleculeSet(null);
    // reset the listener
    listener.reset();
    Assert.assertFalse(listener.getChanged());
    // changing the set must *not* trigger a change event in the IChemModel
    molSet.addAtomContainer(chemObject.getBuilder().newInstance(IAtomContainer.class));
    Assert.assertFalse(listener.getChanged());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) AbstractChemModelTest(org.openscience.cdk.test.interfaces.AbstractChemModelTest) Test(org.junit.Test)

Aggregations

IChemModel (org.openscience.cdk.interfaces.IChemModel)138 Test (org.junit.Test)97 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)85 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)80 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)53 IChemFile (org.openscience.cdk.interfaces.IChemFile)50 InputStream (java.io.InputStream)46 ChemFile (org.openscience.cdk.ChemFile)30 CMLReader (org.openscience.cdk.io.CMLReader)26 IAtom (org.openscience.cdk.interfaces.IAtom)24 ICrystal (org.openscience.cdk.interfaces.ICrystal)21 IOException (java.io.IOException)19 IRingSet (org.openscience.cdk.interfaces.IRingSet)18 CDKException (org.openscience.cdk.exception.CDKException)17 IReaction (org.openscience.cdk.interfaces.IReaction)17 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)17 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)13 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)12 AbstractChemModelTest (org.openscience.cdk.test.interfaces.AbstractChemModelTest)11 ChemObject (org.openscience.cdk.ChemObject)10