use of org.openscience.cdk.silent.AtomContainerSet in project ambit-mirror by ideaconsult.
the class DelimitedFileReader method readSetOfMolecules.
private IAtomContainerSet readSetOfMolecules() {
try {
IAtomContainerSet som = new AtomContainerSet();
IteratingDelimitedFileReader reader = new IteratingDelimitedFileReader(input, format);
while (reader.hasNext()) {
Object object = reader.next();
if (object instanceof IAtomContainer)
som.addAtomContainer((IAtomContainer) object);
}
reader.close();
return som;
} catch (Exception x) {
logger.error(x);
return null;
}
}
use of org.openscience.cdk.silent.AtomContainerSet in project ambit-mirror by ideaconsult.
the class MoleculeEditAction method getMoleculeForEdit.
protected IAtomContainerSet getMoleculeForEdit(IAtomContainer atomContainer) throws Exception {
if (atomContainer == null)
return null;
if (atomContainer instanceof QueryAtomContainer) {
return null;
}
IAtomContainerSet molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer);
IAtomContainerSet m = new AtomContainerSet();
for (int i = 0; i < molecules.getAtomContainerCount(); i++) {
IAtomContainer a = molecules.getAtomContainer(i);
if (!GeometryTools.has2DCoordinates(a)) {
if (sdg == null)
sdg = new StructureDiagramGenerator();
sdg.setMolecule((IAtomContainer) a);
sdg.generateCoordinates(new Vector2d(0, 1));
molecules.replaceAtomContainer(i, sdg.getMolecule());
}
m.addAtomContainer(molecules.getAtomContainer(i));
}
if (// otherwise JChemPaint crashes
m.getAtomContainerCount() == 0)
m.addAtomContainer(MoleculeTools.newMolecule(DefaultChemObjectBuilder.getInstance()));
return m;
}
use of org.openscience.cdk.silent.AtomContainerSet in project ambit-mirror by ideaconsult.
the class StructureEditorProcessor method process.
@Override
public String process(IStructureRecord record) throws AmbitException {
try {
MOL_TYPE mtype = MOL_TYPE.valueOf(record.getFormat());
IAtomContainer mol = null;
switch(mtype) {
case SDF:
{
MoleculeReader reader = new MoleculeReader();
mol = reader.process(record);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
reader = null;
break;
}
case CSV:
{
// smiles
SmilesParserWrapper p = SmilesParserWrapper.getInstance(SMILES_PARSER.CDK);
mol = p.parseSmiles(record.getContent());
break;
}
default:
throw new AmbitException("Unsupported format");
}
// actions
if (mol != null && mol.getAtomCount() > 0)
switch(command) {
case layout:
{
IAtomContainerSet molecules = new AtomContainerSet();
CompoundImageTools cit = new CompoundImageTools();
cit.generate2D(mol, true, molecules);
mol = MoleculeTools.newAtomContainer(mol.getBuilder());
for (IAtomContainer m : molecules.atomContainers()) {
mol.add(m);
}
break;
}
case aromatize:
if (mol != null)
CDKHueckelAromaticityDetector.detectAromaticity(mol);
break;
case dearomatize:
if (mol != null) {
Kekulization.kekulize(mol);
for (IBond bond : mol.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
}
break;
default:
throw new AmbitException("Unknown command");
}
StringWriter w = new StringWriter();
SDFWriter writer = new SDFWriter(w);
writer.write(mol);
writer.close();
return w.toString();
} catch (AmbitException x) {
throw x;
} catch (Exception x) {
throw new AmbitException(x);
}
}
use of org.openscience.cdk.silent.AtomContainerSet in project cdk by cdk.
the class CrossoverMachineTest method testdoCrossover_IAtomContainer.
@Test
public void testdoCrossover_IAtomContainer() throws Exception {
String filename = "c10h16isomers.smi";
InputStream ins = this.getClass().getResourceAsStream(filename);
SMILESReader reader = new SMILESReader(ins);
IAtomContainerSet som = reader.read(new AtomContainerSet());
Assert.assertEquals("We must have read 99 structures", 99, som.getAtomContainerCount());
CrossoverMachine cm = new CrossoverMachine();
String correctFormula = "C10H16";
int errorcount = 0;
for (int i = 0; i < som.getAtomContainerCount(); i++) {
int[] hydrogencount1 = new int[4];
for (IAtom atom : som.getAtomContainer(i).atoms()) {
hydrogencount1[atom.getImplicitHydrogenCount()]++;
}
for (int k = i + 1; k < som.getAtomContainerCount(); k++) {
try {
List<IAtomContainer> result = cm.doCrossover(som.getAtomContainer(i), som.getAtomContainer(k));
int[] hydrogencount2 = new int[4];
for (IAtom atom : som.getAtomContainer(k).atoms()) {
hydrogencount2[atom.getImplicitHydrogenCount()]++;
}
Assert.assertEquals("Result size must be 2", 2, result.size());
for (int l = 0; l < 2; l++) {
IAtomContainer ac = result.get(l);
Assert.assertTrue("Result must be connected", ConnectivityChecker.isConnected(ac));
Assert.assertEquals("Molecular formula must be the same as" + "of the input", MolecularFormulaManipulator.getString(MolecularFormulaManipulator.getMolecularFormula(ac)), correctFormula);
int[] hydrogencountresult = new int[4];
int hcounttotal = 0;
for (IAtom atom : result.get(l).atoms()) {
hydrogencountresult[atom.getImplicitHydrogenCount()]++;
hcounttotal += atom.getImplicitHydrogenCount();
}
if (hydrogencount1[0] == hydrogencount2[0])
Assert.assertEquals("Hydrogen count of the result must" + " be same as of input", hydrogencount1[0], hydrogencountresult[0]);
if (hydrogencount1[1] == hydrogencount2[1])
Assert.assertEquals("Hydrogen count of the result must" + " be same as of input", hydrogencount1[1], hydrogencountresult[1]);
if (hydrogencount1[2] == hydrogencount2[2])
Assert.assertEquals("Hydrogen count of the result must" + " be same as of input", hydrogencount1[2], hydrogencountresult[2]);
if (hydrogencount1[3] == hydrogencount2[3])
Assert.assertEquals("Hydrogen count of the result must" + " be same as of input", hydrogencount1[3], hydrogencountresult[3]);
Assert.assertEquals(16, hcounttotal);
}
} catch (CDKException ex) {
errorcount++;
}
}
}
Assert.assertTrue("We tolerate up to 300 errors", errorcount < 300);
}
use of org.openscience.cdk.silent.AtomContainerSet in project cdk by cdk.
the class CML2WriterTest method testMoleculeSetID.
@Test
public void testMoleculeSetID() throws Exception {
StringWriter writer = new StringWriter();
IAtomContainerSet moleculeSet = new AtomContainerSet();
moleculeSet.setID("ms0");
CMLWriter cmlWriter = new CMLWriter(writer);
cmlWriter.write(moleculeSet);
cmlWriter.close();
String cmlContent = writer.toString();
logger.debug("****************************** testReactionCustomization()");
logger.debug(cmlContent);
logger.debug("******************************");
Assert.assertTrue(cmlContent.contains("<moleculeList convention=\"cdk:moleculeSet\" id=\"ms0"));
}
Aggregations