use of org.openscience.cdk.inchi.InChIGenerator in project MetFragRelaunched by ipb-halle.
the class GetRankOfCandidateCSV method calculateInchiKey.
/**
* @param con
* @return
* @throws CDKException
*/
public static String calculateInchiKey(IAtomContainer con) throws CDKException {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(con);
CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(con.getBuilder());
for (int i = 0; i < con.getAtomCount(); i++) {
try {
hAdder.addImplicitHydrogens(con, con.getAtom(i));
} catch (CDKException e) {
continue;
}
}
AtomContainerManipulator.convertImplicitToExplicitHydrogens(con);
InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
InChIGenerator gen = factory.getInChIGenerator(con);
return gen.getInchiKey().split("-")[0];
}
use of org.openscience.cdk.inchi.InChIGenerator in project MetFragRelaunched by ipb-halle.
the class GetRankOfCandidatePSV method calculateInchiKey.
/**
* @param con
* @return
* @throws CDKException
*/
public static String calculateInchiKey(IAtomContainer con) throws CDKException {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(con);
CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(con.getBuilder());
for (int i = 0; i < con.getAtomCount(); i++) {
try {
hAdder.addImplicitHydrogens(con, con.getAtom(i));
} catch (CDKException e) {
continue;
}
}
AtomContainerManipulator.convertImplicitToExplicitHydrogens(con);
InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
InChIGenerator gen = factory.getInChIGenerator(con);
return gen.getInchiKey().split("-")[0];
}
use of org.openscience.cdk.inchi.InChIGenerator in project bacting by egonw.
the class InChIManager method generate.
/**
* Generates an InChI for the given {@link IMolecule}, using the given options.
* This options String consists of one or more, space-delimited options, such as FixedH.
*
* @param molecule the {@link IMolecule} to create the InChI for
* @return an {@link InChI} object
* @throws Exception
*/
public InChI generate(IMolecule molecule, String options) throws Exception {
if (!isAvailable()) {
return InChI.FAILED_TO_CALCULATE;
}
Object adapted = molecule.getAdapter(IAtomContainer.class);
if (adapted != null) {
IAtomContainer container = (IAtomContainer) adapted;
IAtomContainer clone = (IAtomContainer) container.clone();
// remove aromaticity flags
for (IAtom atom : clone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false);
for (IBond bond : clone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
InChIGenerator gen = factory.getInChIGenerator(clone, options);
InchiStatus status = gen.getStatus();
if (status == InchiStatus.SUCCESS || status == InchiStatus.WARNING) {
InChI inchi = new InChI();
inchi.setValue(gen.getInchi());
inchi.setKey(gen.getInchiKey());
return inchi;
} else {
throw new InvalidParameterException("Error while generating InChI (" + status + "): " + gen.getMessage());
}
} else {
throw new InvalidParameterException("Given molecule must be a CDKMolecule");
}
}
Aggregations