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