Search in sources :

Example 6 with ChemModel

use of org.openscience.cdk.ChemModel in project cdk by cdk.

the class GhemicalReaderTest method testExample.

@Test
public void testExample() throws Exception {
    String testfile = "!Header mm1gp 100\n" + "!Info 1\n" + "!Atoms 6\n" + "0 6 \n" + "1 6 \n" + "2 1 \n" + "3 1 \n" + "4 1 \n" + "5 1 \n" + "!Bonds 5\n" + "1 0 D \n" + "2 0 S \n" + "3 0 S \n" + "4 1 S \n" + "5 1 S \n" + "!Coord\n" + "0 0.06677 -0.00197151 4.968e-07 \n" + "1 -0.0667699 0.00197154 -5.19252e-07 \n" + "2 0.118917 -0.097636 2.03406e-06 \n" + "3 0.124471 0.0904495 -4.84021e-07 \n" + "4 -0.118917 0.0976359 -2.04017e-06 \n" + "5 -0.124471 -0.0904493 5.12591e-07 \n" + "!Charges\n" + "0 -0.2\n" + "1 -0.2\n" + "2 0.1\n" + "3 0.1\n" + "4 0.1\n" + "5 0.1\n" + "!End";
    StringReader stringReader = new StringReader(testfile);
    GhemicalMMReader reader = new GhemicalMMReader(stringReader);
    ChemModel model = (ChemModel) reader.read((ChemObject) new ChemModel());
    reader.close();
    Assert.assertNotNull(model);
    Assert.assertNotNull(model.getMoleculeSet());
    IAtomContainerSet som = model.getMoleculeSet();
    Assert.assertNotNull(som);
    Assert.assertEquals(1, som.getAtomContainerCount());
    IAtomContainer m = som.getAtomContainer(0);
    Assert.assertNotNull(m);
    Assert.assertEquals(6, m.getAtomCount());
    Assert.assertEquals(5, m.getBondCount());
    // test reading of formal charges
    org.openscience.cdk.interfaces.IAtom a = m.getAtom(0);
    Assert.assertNotNull(a);
    Assert.assertEquals(6, a.getAtomicNumber().intValue());
    Assert.assertEquals(-0.2, a.getCharge(), 0.01);
    Assert.assertEquals(0.06677, a.getPoint3d().x, 0.01);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemModel(org.openscience.cdk.ChemModel) ChemObject(org.openscience.cdk.ChemObject) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) StringReader(java.io.StringReader) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 7 with ChemModel

use of org.openscience.cdk.ChemModel in project cdk by cdk.

the class ExtraReaderFactoryTest method expectReader.

void expectReader(String filename, IResourceFormat expectedFormat) throws Exception {
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    Assert.assertNotNull("Cannot find file: " + filename, ins);
    if (expectedFormat instanceof IChemFormatMatcher) {
        factory.registerFormat((IChemFormatMatcher) expectedFormat);
    }
    ISimpleChemObjectReader reader = factory.createReader(ins);
    Assert.assertNotNull(reader);
    Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName());
    // now try reading something from it
    IChemObject[] objects = { new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction() };
    boolean read = false;
    for (int i = 0; (i < objects.length && !read); i++) {
        if (reader.accepts(objects[i].getClass())) {
            IChemObject chemObject = reader.read(objects[i]);
            Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it", chemObject);
            read = true;
        }
    }
    Assert.assertTrue("Reading an IChemObject from the Reader did not work properly.", read);
}
Also used : IChemFormatMatcher(org.openscience.cdk.io.formats.IChemFormatMatcher) IChemObject(org.openscience.cdk.interfaces.IChemObject) ChemModel(org.openscience.cdk.ChemModel) AtomContainer(org.openscience.cdk.AtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) Reaction(org.openscience.cdk.Reaction)

Example 8 with ChemModel

use of org.openscience.cdk.ChemModel in project cdk by cdk.

the class CMLRoundTripTest method testChemModel.

/**
 * @cdk.bug 1455346
 */
@Test
public void testChemModel() throws Exception {
    ChemModel model = new ChemModel();
    IAtomContainerSet moleculeSet = new AtomContainerSet();
    IAtomContainer mol = new AtomContainer();
    PseudoAtom atom = new PseudoAtom("N");
    mol.addAtom(atom);
    moleculeSet.addAtomContainer(mol);
    model.setMoleculeSet(moleculeSet);
    IChemModel roundTrippedModel = CMLRoundTripTool.roundTripChemModel(convertor, model);
    IAtomContainerSet roundTrippedMolSet = roundTrippedModel.getMoleculeSet();
    Assert.assertNotNull(roundTrippedMolSet);
    Assert.assertEquals(1, roundTrippedMolSet.getAtomContainerCount());
    IAtomContainer roundTrippedMolecule = roundTrippedMolSet.getAtomContainer(0);
    Assert.assertNotNull(roundTrippedMolecule);
    Assert.assertEquals(1, roundTrippedMolecule.getAtomCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IPseudoAtom(org.openscience.cdk.interfaces.IPseudoAtom) PseudoAtom(org.openscience.cdk.PseudoAtom) Test(org.junit.Test)

Example 9 with ChemModel

use of org.openscience.cdk.ChemModel in project cdk by cdk.

the class INChIHandler method startDocument.

@Override
public void startDocument() {
    chemFile = new ChemFile();
    chemSequence = new ChemSequence();
    chemModel = new ChemModel();
    setOfMolecules = new AtomContainerSet();
}
Also used : ChemSequence(org.openscience.cdk.ChemSequence) ChemModel(org.openscience.cdk.ChemModel) ChemFile(org.openscience.cdk.ChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AtomContainerSet(org.openscience.cdk.AtomContainerSet)

Example 10 with ChemModel

use of org.openscience.cdk.ChemModel in project cdk by cdk.

the class PDBReaderFactoryTest method expectReader.

void expectReader(String filename, IResourceFormat expectedFormat) throws Exception {
    InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
    Assert.assertNotNull("Cannot find file: " + filename, ins);
    if (expectedFormat instanceof IChemFormatMatcher) {
        factory.registerFormat((IChemFormatMatcher) expectedFormat);
    }
    ISimpleChemObjectReader reader = factory.createReader(ins);
    Assert.assertNotNull(reader);
    Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName());
    // now try reading something from it
    IChemObject[] objects = { new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction() };
    boolean read = false;
    for (int i = 0; (i < objects.length && !read); i++) {
        if (reader.accepts(objects[i].getClass())) {
            IChemObject chemObject = reader.read(objects[i]);
            Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it", chemObject);
            read = true;
        }
    }
    Assert.assertTrue("Reading an IChemObject from the Reader did not work properly.", read);
}
Also used : IChemFormatMatcher(org.openscience.cdk.io.formats.IChemFormatMatcher) IChemObject(org.openscience.cdk.interfaces.IChemObject) ChemModel(org.openscience.cdk.ChemModel) AtomContainer(org.openscience.cdk.AtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) Reaction(org.openscience.cdk.Reaction)

Aggregations

ChemModel (org.openscience.cdk.ChemModel)16 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)12 IChemModel (org.openscience.cdk.interfaces.IChemModel)12 AtomContainer (org.openscience.cdk.AtomContainer)10 Test (org.junit.Test)9 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)9 Reaction (org.openscience.cdk.Reaction)8 InputStream (java.io.InputStream)6 IReaction (org.openscience.cdk.interfaces.IReaction)6 Atom (org.openscience.cdk.Atom)5 Bond (org.openscience.cdk.Bond)5 ChemFile (org.openscience.cdk.ChemFile)5 ReactionSet (org.openscience.cdk.ReactionSet)5 IAtom (org.openscience.cdk.interfaces.IAtom)5 IBond (org.openscience.cdk.interfaces.IBond)5 IChemObject (org.openscience.cdk.interfaces.IChemObject)5 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)5 AtomContainerSet (org.openscience.cdk.AtomContainerSet)4 Before (org.junit.Before)3 ChemObject (org.openscience.cdk.ChemObject)3