use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.
the class TestTautomersFromSDF method test_CHEMBLSDF.
public void test_CHEMBLSDF(String resource) throws Exception {
URL uri = TestTautomersFromSDF.class.getResource(resource);
Assert.assertNotNull(uri);
File infile = new File(uri.getFile());
Assert.assertNotNull(infile);
Assert.assertTrue(infile.exists());
MoleculeReader molReader = new MoleculeReader();
TautomerProcessor tautomers = new TautomerProcessor(null);
tautomers.setCallback(new DefaultAmbitProcessor<IAtomContainer, IAtomContainer>() {
int no_rank;
@Override
public IAtomContainer process(IAtomContainer target) throws Exception {
Object rank = target.getProperty(TautomerConst.TAUTOMER_RANK);
if (rank == null) {
rank = target.getProperty(TautomerConst.CACTVS_ENERGY_RANK);
if (rank == null) {
System.out.println();
no_rank++;
if (no_rank > 1)
throw new Exception(String.format("More than one (%d) structure without rank ! [%s]", no_rank, target.getProperties()));
}
}
return target;
}
@Override
public void close() throws Exception {
Assert.assertTrue(no_rank <= 1);
}
});
IIteratingChemObjectReader<IChemObject> reader = null;
try {
reader = FileInputState.getReader(infile);
// InputStreamReader(in));
while (reader.hasNext()) {
if (reader instanceof IRawReader) {
IStructureRecord record = ((IRawReader<IStructureRecord>) reader).nextRecord();
IAtomContainer mol = molReader.process(record);
IAtomContainer tautomer = tautomers.process(mol);
tautomer.addProperties(mol.getProperties());
// return normalizer.process(record);
StringWriter w = new StringWriter();
SDFWriter sdfwriter = new SDFWriter(w);
sdfwriter.write(tautomer);
sdfwriter.close();
record.setContent(w.toString());
record.setType(STRUC_TYPE.D2noH);
// System.out.println(record.getContent());
}
}
} catch (Exception x) {
throw x;
} finally {
if (reader != null)
reader.close();
}
}
use of org.openscience.cdk.interfaces.IChemObject in project cdk by cdk.
the class QueryAtomContainerCreator method suppressQueryHydrogens.
public static IAtomContainer suppressQueryHydrogens(IAtomContainer mol) {
// pre-checks
for (IAtom atom : mol.atoms()) {
if (!(AtomRef.deref(atom) instanceof QueryAtom))
throw new IllegalArgumentException("Non-query atoms found!");
}
for (IBond bond : mol.bonds()) {
if (!(BondRef.deref(bond) instanceof QueryBond))
throw new IllegalArgumentException("Non-query bonds found!");
}
Map<IChemObject, IChemObject> plainHydrogens = new HashMap<>();
for (IAtom atom : mol.atoms()) {
int hcnt = 0;
for (IAtom nbor : mol.getConnectedAtomsList(atom)) {
QueryAtom qnbor = (QueryAtom) AtomRef.deref(nbor);
if (mol.getConnectedBondsCount(nbor) == 1 && isSimpleHydrogen(qnbor.getExpression())) {
hcnt++;
plainHydrogens.put(nbor, atom);
}
}
if (hcnt > 0) {
QueryAtom qatom = (QueryAtom) AtomRef.deref(atom);
Expr e = qatom.getExpression();
Expr hexpr = new Expr();
for (int i = 0; i < hcnt; i++) hexpr.and(new Expr(Expr.Type.TOTAL_H_COUNT, i).negate());
e.and(hexpr);
}
}
// nothing to do
if (plainHydrogens.isEmpty())
return mol;
IAtomContainer res = new QueryAtomContainer(mol.getBuilder());
for (IAtom atom : mol.atoms()) {
if (!plainHydrogens.containsKey(atom))
res.addAtom(atom);
}
for (IBond bond : mol.bonds()) {
if (!plainHydrogens.containsKey(bond.getBegin()) && !plainHydrogens.containsKey(bond.getEnd()))
res.addBond(bond);
}
for (IStereoElement se : mol.stereoElements()) {
res.addStereoElement(se.map(plainHydrogens));
}
return res;
}
use of org.openscience.cdk.interfaces.IChemObject in project cdk by cdk.
the class ChemObjectTestHelper method testClone_ChemObjectListeners.
public static void testClone_ChemObjectListeners(IChemObject chemObject) throws Exception {
ChemObjectListener listener = new ChemObjectListener();
chemObject.addListener(listener);
IChemObject chemObject2 = (IChemObject) chemObject.clone();
// test lack of cloning of listeners
Assert.assertEquals(0, chemObject.getListenerCount());
Assert.assertEquals(0, chemObject2.getListenerCount());
}
use of org.openscience.cdk.interfaces.IChemObject in project cdk by cdk.
the class MappingTest method testMapping_IChemObject_IChemObject.
@Test
public void testMapping_IChemObject_IChemObject() {
IChemObject object = newChemObject();
IMapping mapping = new Mapping(object.getBuilder().newInstance(IAtom.class), object.getBuilder().newInstance(IAtom.class));
Assert.assertNotNull(mapping);
}
use of org.openscience.cdk.interfaces.IChemObject in project cdk by cdk.
the class BondTest method testBond_IAtom_IAtom.
@Test
public void testBond_IAtom_IAtom() {
IChemObject object = newChemObject();
IAtom c = object.getBuilder().newInstance(IAtom.class, "C");
IAtom o = object.getBuilder().newInstance(IAtom.class, "O");
IBond bond = new Bond(c, o);
Assert.assertEquals(2, bond.getAtomCount());
Assert.assertEquals(c, bond.getBegin());
Assert.assertEquals(o, bond.getEnd());
Assert.assertEquals(IBond.Order.SINGLE, bond.getOrder());
Assert.assertEquals(IBond.Stereo.NONE, bond.getStereo());
}
Aggregations