Search in sources :

Example 21 with AtomContainerSet

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

the class SDFWriterTest method testWrite_IAtomContainerSet_Properties.

@Test
public void testWrite_IAtomContainerSet_Properties() throws Exception {
    StringWriter writer = new StringWriter();
    IAtomContainerSet molSet = new AtomContainerSet();
    IAtomContainer molecule = new AtomContainer();
    molecule.addAtom(new Atom("C"));
    molecule.setProperty("foo", "bar");
    molSet.addAtomContainer(molecule);
    SDFWriter sdfWriter = new SDFWriter(writer);
    sdfWriter.write(molSet);
    sdfWriter.close();
    Assert.assertTrue(writer.toString().contains("<foo>"));
    Assert.assertTrue(writer.toString().contains("bar"));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StringWriter(java.io.StringWriter) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) ChemObjectWriterTest(org.openscience.cdk.test.io.ChemObjectWriterTest) Test(org.junit.Test)

Example 22 with AtomContainerSet

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

the class SDFWriterTest method testWrite_IAtomContainerSet_MultIAtomContainer.

@Test
public void testWrite_IAtomContainerSet_MultIAtomContainer() throws Exception {
    StringWriter writer = new StringWriter();
    IAtomContainerSet molSet = new AtomContainerSet();
    IAtomContainer molecule = new AtomContainer();
    molecule.addAtom(new Atom("C"));
    molSet.addAtomContainer(molecule);
    molecule = new AtomContainer();
    molecule.addAtom(new Atom("C"));
    molSet.addAtomContainer(molecule);
    SDFWriter sdfWriter = new SDFWriter(writer);
    sdfWriter.write(molSet);
    sdfWriter.close();
    Assert.assertTrue(writer.toString().contains("$$$$"));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StringWriter(java.io.StringWriter) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) ChemObjectWriterTest(org.openscience.cdk.test.io.ChemObjectWriterTest) Test(org.junit.Test)

Example 23 with AtomContainerSet

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

the class MoleculeSetManipulatorTest method testRemoveAtomAndConnectedElectronContainers_IAtomContainerSet_IAtom.

@Test
public void testRemoveAtomAndConnectedElectronContainers_IAtomContainerSet_IAtom() {
    IAtomContainerSet ms = new AtomContainerSet();
    IAtomContainer mol = new AtomContainer();
    mol.addAtom(new Atom("O"));
    mol.addAtom(new Atom("O"));
    mol.addBond(0, 1, IBond.Order.DOUBLE);
    IAtom atom = mol.getAtom(0);
    ms.addAtomContainer(mol);
    IAtom otherAtom = new Atom("O");
    MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(ms, otherAtom);
    Assert.assertEquals(1, MoleculeSetManipulator.getBondCount(ms));
    Assert.assertEquals(2, MoleculeSetManipulator.getAtomCount(ms));
    MoleculeSetManipulator.removeAtomAndConnectedElectronContainers(ms, atom);
    Assert.assertEquals(0, MoleculeSetManipulator.getBondCount(ms));
    Assert.assertEquals(1, MoleculeSetManipulator.getAtomCount(ms));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Atom(org.openscience.cdk.Atom) IAtom(org.openscience.cdk.interfaces.IAtom) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 24 with AtomContainerSet

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

the class ChemFileManipulatorTest method setUp.

@Before
public void setUp() {
    molecule1 = new AtomContainer();
    atomInMol1 = new Atom("Cl");
    molecule1.addAtom(atomInMol1);
    molecule1.addAtom(new Atom("Cl"));
    bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1));
    molecule1.addBond(bondInMol1);
    molecule2 = new AtomContainer();
    atomInMol2 = new Atom("O");
    atomInMol2.setImplicitHydrogenCount(2);
    molecule2.addAtom(atomInMol2);
    moleculeSet = new AtomContainerSet();
    moleculeSet.addAtomContainer(molecule1);
    moleculeSet.addAtomContainer(molecule2);
    reaction = new Reaction();
    reaction.addReactant(molecule1);
    reaction.addProduct(molecule2);
    reactionSet = new ReactionSet();
    reactionSet.addReaction(reaction);
    chemModel = new ChemModel();
    chemModel.setMoleculeSet(moleculeSet);
    chemModel.setReactionSet(reactionSet);
    chemSequence1 = new ChemSequence();
    chemSequence1.addChemModel(chemModel);
    chemSequence2 = new ChemSequence();
    chemFile = new ChemFile();
    chemFile.addChemSequence(chemSequence1);
    chemFile.addChemSequence(chemSequence2);
}
Also used : ChemSequence(org.openscience.cdk.ChemSequence) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IReactionSet(org.openscience.cdk.interfaces.IReactionSet) ReactionSet(org.openscience.cdk.ReactionSet) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) Reaction(org.openscience.cdk.Reaction) IReaction(org.openscience.cdk.interfaces.IReaction) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Before(org.junit.Before)

Example 25 with AtomContainerSet

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

the class CMLRoundTripTest method testMoleculeSet.

@Test
public void testMoleculeSet() throws Exception {
    IAtomContainerSet list = new AtomContainerSet();
    list.addAtomContainer(new AtomContainer());
    list.addAtomContainer(new AtomContainer());
    IChemModel model = new ChemModel();
    model.setMoleculeSet(list);
    IChemModel roundTripped = CMLRoundTripTool.roundTripChemModel(convertor, model);
    IAtomContainerSet newList = roundTripped.getMoleculeSet();
    Assert.assertNotNull(newList);
    Assert.assertEquals(2, newList.getAtomContainerCount());
    Assert.assertNotNull(newList.getAtomContainer(0));
    Assert.assertNotNull(newList.getAtomContainer(1));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IChemModel(org.openscience.cdk.interfaces.IChemModel) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) Test(org.junit.Test)

Aggregations

AtomContainerSet (org.openscience.cdk.AtomContainerSet)30 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)30 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)26 Test (org.junit.Test)18 AtomContainer (org.openscience.cdk.AtomContainer)16 IAtom (org.openscience.cdk.interfaces.IAtom)12 Atom (org.openscience.cdk.Atom)11 InputStream (java.io.InputStream)6 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)6 StringWriter (java.io.StringWriter)5 ChemObjectWriterTest (org.openscience.cdk.test.io.ChemObjectWriterTest)5 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 ArrayList (java.util.ArrayList)4 ChemModel (org.openscience.cdk.ChemModel)4 CDKException (org.openscience.cdk.exception.CDKException)4 SDFWriter (org.openscience.cdk.io.SDFWriter)4 IteratingSMILESReader (org.openscience.cdk.io.iterator.IteratingSMILESReader)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3