use of org.openscience.cdk.interfaces.IChemSequence 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.IChemSequence 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.IChemSequence in project cdk by cdk.
the class ChemSequenceTest method testChemSequence.
@Test
public void testChemSequence() {
IChemSequence cs = new ChemSequence();
Assert.assertNotNull(cs);
}
use of org.openscience.cdk.interfaces.IChemSequence in project cdk by cdk.
the class ChemFile method toString.
/**
* Returns a String representation of this class. It implements
* RFC #9.
*
*@return String representation of the Object
*/
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("ChemFile(#S=");
buffer.append(chemSequenceCount);
if (chemSequenceCount > 0) {
for (IChemSequence iChemSequence : chemSequences()) {
buffer.append(", ");
buffer.append(iChemSequence.toString());
}
}
buffer.append(')');
return buffer.toString();
}
use of org.openscience.cdk.interfaces.IChemSequence in project cdk by cdk.
the class ConjugatedPiSystemsDetectorTest method readCMLMolecule.
/**
* A unit test for JUnit
*
* @cdk.inchi
*
*@return Description of the Return Value
*/
private IAtomContainer readCMLMolecule(String filename) throws Exception {
IAtomContainer mol;
logger.debug("Filename: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
CMLReader reader = new CMLReader(ins);
IChemFile file = reader.read(new ChemFile());
Assert.assertNotNull(file);
Assert.assertEquals(1, file.getChemSequenceCount());
IChemSequence sequence = file.getChemSequence(0);
Assert.assertNotNull(sequence);
Assert.assertEquals(1, sequence.getChemModelCount());
IChemModel chemModel = sequence.getChemModel(0);
Assert.assertNotNull(chemModel);
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
Assert.assertNotNull(moleculeSet);
Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
mol = moleculeSet.getAtomContainer(0);
Assert.assertNotNull(mol);
return mol;
}
Aggregations