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);
}
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);
}
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());
}
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();
}
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);
}
Aggregations