use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.
the class ReactionSequence method generateSequenceStepForReactionInstance.
public void generateSequenceStepForReactionInstance(ReactionSequenceLevel level, int moleculeIndex, GenericReactionInstance gri) throws Exception {
ReactionSequenceStep step = new ReactionSequenceStep();
step.reaction = gri.reaction;
// IAtomContainer mol = level.molecules.get(moleculeIndex);
step.reactionScore = gri.reactionScore;
IAtomContainerSet productFrags = ConnectivityChecker.partitionIntoMolecules(gri.products);
step.outputMolecules = new ArrayList<IAtomContainer>();
for (IAtomContainer frag : productFrags.atomContainers()) {
step.outputMolecules.add(frag);
String inchiKey = setMoleculeInchiKey(frag);
registerMolInchiKey(frag, inchiKey, level.levelIndex + 1);
// Set new molecule status
if (usedInchies.get(inchiKey).molecules.size() > 1)
setMoleculeStatus(frag, MoleculeStatus.EQUIVALENT_TO_OTHER_MOLECULE);
else {
if (startMatDB.isStartingMaterial(inchiKey))
setMoleculeStatus(frag, MoleculeStatus.STARTING_MATERIAL);
else
setMoleculeStatus(frag, MoleculeStatus.ADDED_TO_LEVEL);
}
}
level.associateStep(moleculeIndex, step);
}
use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.
the class ReactionSequence method getMaxProductFragment.
IAtomContainer getMaxProductFragment(IAtomContainer products) {
int maxSize = -1;
IAtomContainer maxFrag = null;
IAtomContainerSet productFrags = ConnectivityChecker.partitionIntoMolecules(products);
for (IAtomContainer frag : productFrags.atomContainers()) if (maxSize < frag.getAtomCount()) {
maxFrag = frag;
maxSize = frag.getAtomCount();
}
return maxFrag;
}
use of org.openscience.cdk.interfaces.IAtomContainerSet 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.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.
the class SmartsManager method fragmentSearchIn.
boolean fragmentSearchIn(IAtomContainer target) throws Exception {
boolean noComponentsSpecified = true;
for (int i = 0; i < parser.fragmentComponents.size(); i++) {
if (parser.fragmentComponents.get(i).intValue() > 0) {
noComponentsSpecified = false;
break;
}
}
if (parser.hasRecursiveSmarts) {
clearQueryRecMatches();
getQueryRecMatches(target);
}
if (// There are no zero level brackets i.e. each
noComponentsSpecified) // fragments maps anywhere
{
for (int i = 0; i < parser.fragments.size(); i++) {
query = parser.fragments.get(i);
if (!mappingIn(target))
return (false);
}
return (true);
}
// Handle Component Level Grouping (zero level brackets are used)
IAtomContainerSet ms = ConnectivityChecker.partitionIntoMolecules(target);
// This is a simple preliminary check
if (ms.getAtomContainerCount() < parser.maxCompNumber)
return (false);
// Each query fragment which is in a component with number > 0 is
// searched individually against
// each target component.
// The query fragments which are not in a zero level brackets (comp.
// number = 0) are searched
// against the "whole target" i.e. to found it at least in on the of the
// target components
compFrags.clear();
boolean res;
for (int i = 0; i < parser.fragments.size(); i++) {
if (parser.fragmentComponents.get(i).intValue() == 0) {
query = parser.fragments.get(i);
res = mappingIn(target);
if (!res)
// This non-component fragment is not found
return (false);
// in the target
} else
// parser.fragmentComponents.get(i));
compFrags.add(new Integer(i));
}
fragMaps = new boolean[compFrags.size()][ms.getAtomContainerCount()];
components = new int[compFrags.size()];
for (int i = 0; i < compFrags.size(); i++) {
components[i] = parser.fragmentComponents.get(compFrags.get(i).intValue()).intValue();
for (int j = 0; j < ms.getAtomContainerCount(); j++) {
query = parser.fragments.get(compFrags.get(i).intValue());
fragMaps[i][j] = mappingIn(ms.getAtomContainer(j));
}
}
// printComponentFrags();
return (checkComponentMapings());
}
use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.
the class SmartsManager method getAllIsomorphismMappings.
public IAtomContainerSet getAllIsomorphismMappings(IAtomContainer target) throws Exception {
IAtomContainerSet s = MoleculeTools.newAtomContainerSet(SilentChemObjectBuilder.getInstance());
if (query == null)
return (s);
if (FlagUseCDKIsomorphismTester) {
if (query.getAtomCount() < 3) {
if (FlagSetSmartsDataForTarget)
parser.setSMARTSData(target);
if (parser.hasRecursiveSmarts) {
clearQueryRecMatches();
getQueryRecMatches(target);
}
}
if (query.getAtomCount() == 1) {
List<IAtom> v = getAtomMappingsFor1AtomQuery(target, query);
for (int i = 0; i < v.size(); i++) {
IAtomContainer c = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
c.addAtom(v.get(i));
s.addAtomContainer(c);
}
return (s);
}
if (query.getAtomCount() == 2) {
return (getAllIsomorphismMappingsFor2AtomQuery(target, query));
}
// The case query.getAtomCount() >= 3
List<List<RMap>> maps = getBondMappings(target);
for (List<RMap> bondMap : maps) {
IAtomContainer c = generateFullIsomorphismMapping(bondMap, target, query);
s.addAtomContainer(c);
}
return (s);
} else // Current Isomorphism Tester is used
{
// TODO
}
return (s);
}
Aggregations