use of ambit2.descriptors.AtomEnvironmentDescriptor in project ambit-mirror by ideaconsult.
the class AtomEnvironmentGenerator method generateProperty.
@Override
public AtomEnvironmentList generateProperty(IAtomContainer atomContainer) throws AmbitException {
try {
IAtomContainer mol = (IAtomContainer) ((IAtomContainer) atomContainer).clone();
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
// atom list - bug?
try {
if (hAdder == null)
hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
hAdder.addImplicitHydrogens(mol);
} catch (Exception x) {
}
CDKHueckelAromaticityDetector.detectAromaticity(mol);
// }
AtomEnvironmentList aeList = new AtomEnvironmentList();
aeList.setNoDuplicates(noDuplicates);
aeParams[AtomEnvironmentDescriptor._param.maxLevel.ordinal()] = maxLevels;
aeDescriptor.setParameters(aeParams);
int[][] aeResult = null;
try {
aeResult = aeDescriptor.doCalculation(mol);
} catch (CDKException x) {
throw new AmbitException(x);
}
for (int a = 0; a < aeResult.length; a++) {
AtomEnvironment atomenv = new AtomEnvironment(maxLevels);
atomenv.setTime_elapsed(System.currentTimeMillis());
aeParams[0] = maxLevels;
atomenv.setTime_elapsed(System.currentTimeMillis() - atomenv.getTime_elapsed());
atomenv.setStatus(1);
atomenv.setSublevel(maxLevels);
// result formatting
atomenv.setAtom_environment(aeResult[a]);
// atomenv.setAtom_environment(aeDescriptor.atomFingerprintToString(aeResult,':'));
atomenv.setCentral_atom(aeDescriptor.atomTypeToString(aeResult[a][1]));
atomenv.setAtomno(a);
aeList.add(atomenv);
// lower level AE
if (isCreateSubLevels())
for (int i = 1; i < atomenv.getLevels(); i++) {
AtomEnvironment subae = atomenv.getSubAtomEnvironment(i);
subae.setSublevel(i);
if (!atomenv.equals(subae))
aeList.add(subae);
}
}
return aeList;
} catch (Exception x) {
logger.log(Level.WARNING, x.getMessage(), x);
}
return null;
}
use of ambit2.descriptors.AtomEnvironmentDescriptor in project ambit-mirror by ideaconsult.
the class AtomEnvironmentDescriptorTest method testAtomEnvironmentDescriptor.
@Test
public void testAtomEnvironmentDescriptor() throws Exception {
AtomEnvironmentDescriptor descriptor = new AtomEnvironmentDescriptor();
int maxLevel = 1;
Object[] params = { new Integer(maxLevel) };
SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
// IAtomContainer mol = sp.parseSmiles("CCCCCC=CCC=CCCCCCCCC(=O)NCCO");
IAtomContainer mol = sp.parseSmiles("C#N");
// IAtomContainer mol = sp.parseSmiles("CCCC(CCC(CCCC(CCCCCCC(CCCCCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CC(CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC)CCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCCCC)CCC)CCC(CC(CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC)CCC)CCC)CCCC(CCC(CCCC(CCCCCCC(CCCCC)CCC)CCC(CCCCC)CCC)CC)CCC)CCC(CCCCC)CCC");
AtomConfigurator typer = new AtomConfigurator();
typer.process(mol);
// AtomContainer mol = sp.parseSmiles("N#CC(=Cc1ccc(O)c(O)c1)C(=O)NCCCNC(=O)C(C#N)=Cc2ccc(O)c(O)c2");
CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
hAdder.addImplicitHydrogens(mol);
descriptor.setParameters(params);
IntegerArrayResult r = (IntegerArrayResult) descriptor.calculate(mol).getValue();
for (int i = 0; i < mol.getAtomCount(); i++) {
if (i == 0) {
// just for test
Object[] parameters = descriptor.getParameters();
AtomTypeFactory factory = (AtomTypeFactory) parameters[AtomEnvironmentDescriptor._param.atomTypeFactory.ordinal()];
IAtomType[] at = factory.getAllAtomTypes();
/*
System.out.print("Sum\tAtomType\t");
for (int j=0; j < factory.getSize(); j++) {
System.out.print(j);
System.out.print(".");
System.out.print(at[j].getAtomTypeName());
System.out.print("\t");
}
*/
// System.out.println("");
Assert.assertTrue(factory.getSize() > 0);
// System.out.println(r.toString());
Assert.assertEquals(mol.getAtomCount() * (maxLevel * (factory.getSize() + 1) + 2), r.length());
}
}
}
use of ambit2.descriptors.AtomEnvironmentDescriptor in project ambit-mirror by ideaconsult.
the class MySelector method testCH3difference.
public void testCH3difference(boolean display) throws Exception {
IMolecularDescriptor descriptor = new AtomEnvironmentDescriptor();
int maxLevel = 3;
Object[] params = { null, new Integer(maxLevel), new Boolean(true), new Boolean(true) };
SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
// IAtomContainer mol = sp.parseSmiles("O=N(=O)c1ccc(O)c(N)c1");
// Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
// IAtomContainer mol1 = sp.parseSmiles("Cc1c(C)c(cc(N)c1(O))N(=O)=O");
IAtomContainer molecule1 = sp.parseSmiles("Nc1c(C)cccc1");
// Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
IAtomContainer molecule2 = sp.parseSmiles("Nc1c(O)cccc1");
// Amino-2nitro-3.4-5 hydroxy-methyl benzene (ANMB)
AtomEnvironmentGenerator g = new AtomEnvironmentGenerator();
g.setNoDuplicates(false);
g.setUseHydrogens(true);
g.setMaxLevels(maxLevel);
AtomEnvironmentList ae = g.generateProperty(molecule1);
AtomEnvironmentList ae1 = g.generateProperty(molecule2);
Collections.sort(ae);
Collections.sort(ae1);
AtomEnvironmentsDistance d = new AtomEnvironmentsDistance();
System.out.println("distance " + d.getDistance(ae, ae1));
Set<AtomEnvironment> set = new TreeSet<AtomEnvironment>();
Set<AtomEnvironment> set1 = new TreeSet<AtomEnvironment>();
for (int i = 0; i < ae.size(); i++) set.add(ae.get(i));
for (int i = 0; i < ae1.size(); i++) set1.add(ae1.get(i));
System.out.println(set);
System.out.println();
System.out.println(set1);
Assert.assertNotSame(set, set1);
Set intersection = (Set) ((TreeSet) set1).clone();
intersection.retainAll(set);
System.out.println("Intersection\t" + intersection.size());
System.out.println(intersection);
if (display)
displayAE(molecule1, ae, molecule2, ae1);
Assert.assertNotNull(ae);
Assert.assertNotNull(ae1);
}
Aggregations