use of ambit2.core.smiles.SmilesParserWrapper in project ambit-mirror by ideaconsult.
the class MoleculeTools method getFingerPrint.
public static BitSet getFingerPrint(String smiles, int fpLength) throws Exception {
SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
IAtomContainer mol = sp.parseSmiles(smiles);
if (fingerprinter == null)
fingerprinter = new Fingerprinter(fpLength);
return fingerprinter.getBitFingerprint(mol).asBitSet();
}
use of ambit2.core.smiles.SmilesParserWrapper in project ambit-mirror by ideaconsult.
the class AtomEnvironmentHammingDistanceTest method testGetDistance.
/**
* Test method for {@link ambit2.similarity.AtomEnvironmentHammingDistance#getDistance(ambit2.data.descriptors.AtomEnvironmentList, ambit2.data.descriptors.AtomEnvironmentList)}.
*/
@Test
public void testGetDistance() throws Exception {
IAtomContainer mol = MoleculeFactory.makeAlkane(3);
IAtomContainer mol1 = MoleculeFactory.makeAlkane(3);
SmilesParserWrapper p = SmilesParserWrapper.getInstance();
IAtomContainer mol2 = p.parseSmiles("CCCC");
AtomEnvironmentGenerator g = new AtomEnvironmentGenerator();
g.setUseHydrogens(true);
g.setMaxLevels(3);
AtomEnvironmentList ae = g.generateProperty(mol);
AtomEnvironmentList ae1 = g.generateProperty(mol1);
AtomEnvironmentList ae2 = g.generateProperty(mol2);
AtomEnvironmentsDistance hd = new AtomEnvironmentsDistance();
Assert.assertEquals(1.0, hd.getDistance(ae, ae1), 1E-10);
Assert.assertEquals(hd.getDistance(ae1, ae), hd.getDistance(ae, ae1), 1E-10);
System.out.println(ae);
System.out.println(ae2);
float d = hd.getDistance(ae, ae2);
// System.out.println(d);
Assert.assertTrue(d < 1.0);
Assert.assertEquals(hd.getDistance(ae2, ae), hd.getDistance(ae1, ae2), 1E-10);
}
use of ambit2.core.smiles.SmilesParserWrapper in project ambit-mirror by ideaconsult.
the class Mopac7WriterTest method testReader2009.
@Test
public void testReader2009() throws Exception {
InputStream in = Mopac7Writer.class.getClassLoader().getResourceAsStream("ambit2/mopac/mopac2009.out");
Mopac7Reader r = new Mopac7Reader(in);
SmilesParserWrapper p = SmilesParserWrapper.getInstance(SMILES_PARSER.CDK);
String smiles = "C=C";
IChemObject m = p.parseSmiles(smiles);
m = r.read(m);
in.close();
Object e = m.getProperty("TOTAL ENERGY");
Assert.assertEquals("-1223.60097", e.toString());
/*
this fails - todo check why
Assert.assertEquals(-9.925,
Double.parseDouble(m.getProperty(DescriptorMopacShell.EHOMO).toString()),
1E-3);
Assert.assertEquals(1.007,
Double.parseDouble(m.getProperty(DescriptorMopacShell.ELUMO).toString()),
1E-3);
*/
for (int i = 0; i < ((IAtomContainer) m).getAtomCount(); i++) {
Assert.assertNotNull(((IAtomContainer) m).getAtom(i).getPoint3d());
}
}
use of ambit2.core.smiles.SmilesParserWrapper 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 ambit2.core.smiles.SmilesParserWrapper in project ambit-mirror by ideaconsult.
the class RendererTest method testFullerene.
@Test
public void testFullerene() throws Exception {
// String smiles =
// "O=C(O)C(N)CCCCNC%31%26C%29C5C3=C%25C=%23C%17=C4C=2c%16c1c%15c%14C%12=C1C=%10C=2C=9C(=C34)C5=C8c%30c7c6c%28C%22=C%21C6=C%13C=%11C7=C8C=9C=%10C=%11C%12=C%13C=%20c%14c%19c%18c%15c(c%16%17)C%24=C%18C=%27C(=C%19C=%20%21)C%22=C(C=%27C(C=%23%24)C%25%26)C%31c%28c%29%30";
// String smiles =
// "NC(=O)C%32=C(N)C(N1C=CC=CC1)=C(C(N)=O)C%31%35C3=C%30C=2c%29c%10C=9C=2C=%26C3=C%34C%27=C8c7c%33c6c(c%28C=5C%31C%30=C4c%29c%11C%12=C4C=5C=%13c%28c%14c6c%15c7C%16=C8C%17=C(C=9C%18C%20c%10c%11C%19C%24=C%12C=%13C=%23C%14=C%15C%25=C%16C(=C%17%18)C%21(C(C(N)=O)=C(C(N)=C(C(N)=O)C%19%20%21)N%22C=CC=CC%22)C%25C=%23%24)C=%26%27)C%32%35C%33%34";
String smiles = "c1ccccc1";
SmilesParserWrapper w = SmilesParserWrapper.getInstance(SMILES_PARSER.CDK);
IAtomContainer a = w.parseSmiles(smiles);
for (int i = 0; i < a.getAtomCount(); i++) {
a.getAtom(i).setID(Integer.toString(i + 1));
}
int[][] aMatrix = PathTools.computeFloydAPSP(AdjacencyMatrix.getMatrix(a));
/*
* System.out.println("%%MatrixMarket matrix coordinate real general"); System
* .out.println(String.format("%d %d %d",a.getAtomCount(),a.getAtomCount
* (),a.getBondCount()));
*/
int count = 0;
double max = 0;
for (int i = 0; i < aMatrix.length; i++) for (int j = i + 1; j < aMatrix[i].length; j++) {
double v = getVal(aMatrix[i][j]);
if (v > max)
max = v;
if (v > 0)
count++;
}
Logger.getGlobal().log(java.util.logging.Level.FINEST, "%%MatrixMarket matrix coordinate real general");
Logger.getGlobal().log(java.util.logging.Level.FINEST, String.format("%d %d %d", aMatrix.length, aMatrix.length, count));
for (int i = 0; i < aMatrix.length; i++) for (int j = i + 1; j < aMatrix[i].length; j++) if (aMatrix[i][j] > 0) {
double v = getVal(aMatrix[i][j]);
Logger.getGlobal().log(java.util.logging.Level.FINEST, String.format("%s %s %f", i + 1, j + 1, v));
}
}
Aggregations