use of org.openscience.cdk.isomorphism.matchers.QueryAtomContainer in project ambit-mirror by ideaconsult.
the class MoleculeEditAction method getMoleculeForEdit.
protected IAtomContainerSet getMoleculeForEdit(IAtomContainer atomContainer) throws Exception {
if (atomContainer == null)
return null;
if (atomContainer instanceof QueryAtomContainer) {
return null;
}
IAtomContainerSet molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer);
IAtomContainerSet m = new AtomContainerSet();
for (int i = 0; i < molecules.getAtomContainerCount(); i++) {
IAtomContainer a = molecules.getAtomContainer(i);
if (!GeometryTools.has2DCoordinates(a)) {
if (sdg == null)
sdg = new StructureDiagramGenerator();
sdg.setMolecule((IAtomContainer) a);
sdg.generateCoordinates(new Vector2d(0, 1));
molecules.replaceAtomContainer(i, sdg.getMolecule());
}
m.addAtomContainer(molecules.getAtomContainer(i));
}
if (// otherwise JChemPaint crashes
m.getAtomContainerCount() == 0)
m.addAtomContainer(MoleculeTools.newMolecule(DefaultChemObjectBuilder.getInstance()));
return m;
}
use of org.openscience.cdk.isomorphism.matchers.QueryAtomContainer 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.QueryAtomContainer in project ambit-mirror by ideaconsult.
the class SmartsParser method newFragment.
void newFragment() {
// A new fragments is started. It is inside
numFragments++;
// "current component"
curFragment = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
fragments.add(curFragment);
fragmentComponents.add(new Integer(curComponent));
}
use of org.openscience.cdk.isomorphism.matchers.QueryAtomContainer in project ambit-mirror by ideaconsult.
the class SmartsParser method parse.
public IQueryAtomContainer parse(String sm) {
smarts = sm;
container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
errors.clear();
nullifyDataFlags();
init();
parse();
return container;
}
use of org.openscience.cdk.isomorphism.matchers.QueryAtomContainer in project ambit-mirror by ideaconsult.
the class SmartsParser method parse.
void parse() {
while ((curChar < nChars) && (errors.size() == 0)) {
if (Character.isLetter(smarts.charAt(curChar))) {
parseAtom();
} else if (Character.isDigit(smarts.charAt(curChar))) {
parseAtomIndex();
} else {
// symbol '%' is handled by
parseSpecialSymbol();
// parseAtomIndex() as well
}
}
// Treat unclosed brackets
if (!brackets.empty())
newError("There are unclosed brackets", -1, "");
// Treat incorrectly used indexes
if (indexes.size() != 0) {
newError("There are unclosed ring indices", -1, "");
Set<Integer> keys = indexes.keySet();
for (Integer key : keys) newError("Ring index " + key + " is unclosed", -1, "");
}
if (directionalBonds.size() > 0)
setDoubleBondsStereoInfo();
// Handle chirality info
List<SmartsAtomExpression> caList = new ArrayList<SmartsAtomExpression>();
for (int i = 0; i < container.getAtomCount(); i++) if (container.getAtom(i) instanceof SmartsAtomExpression) {
SmartsAtomExpression sa = (SmartsAtomExpression) container.getAtom(i);
handleChirality(sa);
if (sa.stereoTokenIndices != null) {
checkChirality(sa, i);
caList.add(sa);
}
}
if (!caList.isEmpty())
container.setProperty("ChiralAtoms", caList);
setNeededDataFlags();
// The global work variables are stored in order to use them again in
// the recursion
// and to preserve the original values for the code after recursion
IQueryAtomContainer container0 = container;
List<IQueryAtomContainer> fragments0 = fragments;
List<Integer> fragmentComponents0 = fragmentComponents;
// Handle recursive smarts
for (int i = 0; i < container0.getAtomCount(); i++) {
if (container0.getAtom(i) instanceof SmartsAtomExpression) {
SmartsAtomExpression sa = (SmartsAtomExpression) container0.getAtom(i);
for (int j = 0; j < sa.recSmartsStrings.size(); j++) {
hasRecursiveSmarts = true;
smarts = sa.recSmartsStrings.get(j);
// New instances of the global working variables are created
// for the recursion process
// This is needed in order to not mess up the original
// containers.
// Generally within recursive SMARTS expression fragments
// and component level groping do not make sense,
// however in the current version the parser will parse this
// information, but it will not be stored any where
container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
fragments = new ArrayList<IQueryAtomContainer>();
fragmentComponents = new ArrayList<Integer>();
init();
insideRecSmarts = true;
parse();
sa.recSmartsContainers.add(container);
insideRecSmarts = false;
}
}
}
// Restoring the global work variables after recursion
container = container0;
fragments = fragments0;
fragmentComponents = fragmentComponents0;
}
Aggregations