use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.
the class QuerySMARTS method prepareScreening.
public void prepareScreening() throws AmbitException {
try {
if (((screening.getValue() == null) && isFp1024_screening()) || ((screening.getFieldname() == null)) && isSk1024_screening()) {
// if ((screening.getValue()==null) || (screening.getFieldname()==null)) {
screening.setPageSize(0);
screening.setPage(0);
SmartsPatternAmbit matcher = new SmartsPatternAmbit(builder);
matcher.setUseCDKIsomorphism(false);
value.setQuery(matcher);
IQueryAtomContainer container = matcher.getQuery();
IAtomContainer atomContainer = smartsToChemObject.process(container);
try {
AtomConfigurator cfg = new AtomConfigurator();
cfg.process(atomContainer);
} catch (Exception x) {
logger.log(Level.FINE, x.getMessage(), x);
}
try {
CDKHueckelAromaticityDetector.detectAromaticity(atomContainer);
} catch (Exception x) {
logger.log(Level.FINE, x.getMessage(), x);
}
if ((atomContainer == null) || (atomContainer.getAtomCount() == 0)) {
screening.setValue(null);
screening.setFieldname(null);
} else {
try {
screening.setValue(fp1024_screening ? fpGenerator.process(atomContainer) : null);
} catch (Exception x) {
screening.setValue(null);
}
try {
screening.setFieldname(sk1024_screening ? skGenerator.process(atomContainer) : null);
} catch (Exception x) {
screening.setFieldname(null);
}
}
}
} catch (AmbitException x) {
throw x;
// screening.setValue(null);
// screening.setFieldname(null);
}
}
use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnContainerToQueryAtomContainer.
public IQueryAtomContainer slnContainerToQueryAtomContainer(SLNContainer slnContainer) {
clearAllErrorsAndWarnings();
IQueryAtomContainer container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
Map<SLNAtom, IQueryAtom> convertedAtoms = new HashMap<SLNAtom, IQueryAtom>();
for (int i = 0; i < slnContainer.getAtomCount(); i++) {
SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
IQueryAtom atom = slnAtomToQueryAtom(slnAtom);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
if (atom == null) {
conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
continue;
}
container.addAtom(atom);
convertedAtoms.put(slnAtom, atom);
}
for (int i = 0; i < slnContainer.getBondCount(); i++) {
SLNBond slnBbond = (SLNBond) slnContainer.getBond(i);
IQueryBond bond = slnBondToQueryBond(slnBbond);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
if (bond == null) {
conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
continue;
}
IAtom[] newAtoms = new IAtom[2];
newAtoms[0] = convertedAtoms.get(slnBbond.getAtom(0));
newAtoms[1] = convertedAtoms.get(slnBbond.getAtom(1));
if (newAtoms[0] == null || newAtoms[1] == null)
// one of the atoms is not converted
continue;
bond.setAtoms(newAtoms);
container.addBond(bond);
}
return container;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.
the class SLN2SMARTS method slnToSmarts.
public String slnToSmarts(String sln) {
reset();
SLNContainer container = slnParser.parse(sln);
String parserErr = slnParser.getErrorMessages();
if (!parserErr.equals("")) {
conversionErrors.add(parserErr);
return null;
}
IQueryAtomContainer query = slnConverter.slnContainerToQueryAtomContainer(container);
String smarts = smartsHelper.toSmarts(query);
conversionErrors.addAll(slnConverter.getConversionErrors());
conversionWarnings.addAll(slnConverter.getConversionWarnings());
return smarts;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.
the class SMIRKSManager method parse.
public SMIRKSReaction parse(String smirks) {
parserErrors.clear();
SMIRKSReaction reaction = new SMIRKSReaction(stco.getBuilder());
// Separate the components of the SMIRKS string
int sep1Pos = smirks.indexOf(">");
if (sep1Pos == -1) {
parserErrors.add("Invalid SMIRKS: missing separators '>'");
return reaction;
}
int sep2Pos = smirks.indexOf(">", sep1Pos + 1);
if (sep2Pos == -1) {
parserErrors.add("Invalid SMIRKS: missing second separator '>'");
return reaction;
}
// Parse the components
int res = 0;
IQueryAtomContainer fragment;
reaction.reactantsSmarts = smirks.substring(0, sep1Pos).trim();
fragment = parseComponent(reaction.reactantsSmarts, "Reactants", reaction.reactantFlags, reaction.reactants, reaction.reactantCLG);
if (fragment == null)
res++;
else {
reaction.reactant = fragment;
if (reaction.reactantFlags.hasRecursiveSmarts)
reaction.reactantRecursiveAtoms = getRecursiveAtoms(fragment);
}
reaction.agentsSmarts = smirks.substring(sep1Pos + 1, sep2Pos).trim();
if (!reaction.agentsSmarts.equals("")) {
fragment = parseComponent(reaction.agentsSmarts, "Agents", reaction.agentFlags, reaction.agents, reaction.agentsCLG);
if (fragment == null)
res++;
else
reaction.agent = fragment;
}
reaction.productsSmarts = smirks.substring(sep2Pos + 1).trim();
fragment = parseComponent(reaction.productsSmarts, "Products", reaction.productFlags, reaction.products, reaction.productsCLG);
if (fragment == null)
res++;
else {
reaction.product = fragment;
if (reaction.productFlags.hasRecursiveSmarts)
reaction.productRecursiveAtoms = getRecursiveAtoms(fragment);
}
if (res > 0)
return reaction;
reaction.checkMappings();
// Check for mapping errors
if (reaction.mapErrors.size() > 0) {
parserErrors.addAll(reaction.mapErrors);
return (reaction);
}
reaction.generateTransformationData(FlagAromaticityTransformation);
if (reaction.mapErrors.isEmpty()) {
// Handle stereo transformation
if (FlagApplyStereoTransformation) {
reaction.generateStereoTransformation();
// reaction.checkStereoTransformation();
}
// Handle H atom transformation
if (FlagHAtomsTransformation)
reaction.generateHAtomTransformation();
}
// Check for errors produced by the generation of transformation data
if (reaction.mapErrors.size() > 0) {
parserErrors.addAll(reaction.mapErrors);
return (reaction);
}
return reaction;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer in project ambit-mirror by ideaconsult.
the class SMIRKSManager method parseComponent.
public IQueryAtomContainer parseComponent(String smarts, String compType, SmartsFlags flags, List<IQueryAtomContainer> fragments, List<Integer> CLG) {
IQueryAtomContainer fragment = parser.parse(smarts);
parser.setNeededDataFlags();
String errorMsg = parser.getErrorMessages();
if (!errorMsg.equals("")) {
parserErrors.add("Invalid " + compType + " part in SMIRKS: " + smarts + " " + errorMsg);
return (null);
}
flags.hasRecursiveSmarts = parser.hasRecursiveSmarts;
flags.mNeedExplicitHData = parser.needExplicitHData();
flags.mNeedNeighbourData = parser.needNeighbourData();
flags.mNeedParentMoleculeData = parser.needParentMoleculeData();
flags.mNeedRingData = parser.needRingData();
flags.mNeedRingData2 = parser.needRingData2();
flags.mNeedValenceData = parser.needValencyData();
for (int i = 0; i < parser.fragments.size(); i++) fragments.add(parser.fragments.get(i));
for (int i = 0; i < parser.fragmentComponents.size(); i++) CLG.add(parser.fragmentComponents.get(i));
return (fragment);
}
Aggregations