Search in sources :

Example 1 with MacroAtomDictionaryObject

use of ambit2.sln.dictionary.MacroAtomDictionaryObject in project ambit-mirror by ideaconsult.

the class Expander method expandMacroAtomDictionaryObject.

public List<IAtom> expandMacroAtomDictionaryObject(MacroAtomDictionaryObject maDO) {
    // Clone all atoms from maDO and add to the expanded container
    List<IAtom> newAtoms = new ArrayList<IAtom>();
    for (int i = 0; i < maDO.container.getAtomCount(); i++) {
        SLNAtom at = (SLNAtom) maDO.container.getAtom(i);
        SLNAtom newAt = at.clone();
        expContainer.addAtom(newAt);
        newAtoms.add(newAt);
    }
    // Also, clone all bonds from maDO and add to the expanded container
    for (int i = 0; i < maDO.container.getBondCount(); i++) {
        SLNBond bo = (SLNBond) maDO.container.getBond(i);
        SLNBond newBo = bo.clone();
        int index0 = maDO.container.indexOf(bo.getAtom(0));
        int index1 = maDO.container.indexOf(bo.getAtom(1));
        newBo.setAtoms(new IAtom[] { newAtoms.get(index0), newAtoms.get(index1) });
        expContainer.addBond(newBo);
    }
    return newAtoms;
}
Also used : ArrayList(java.util.ArrayList) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with MacroAtomDictionaryObject

use of ambit2.sln.dictionary.MacroAtomDictionaryObject in project ambit-mirror by ideaconsult.

the class SLNParser method parseMacroAtomDictionaryObject.

public ISLNDictionaryObject parseMacroAtomDictionaryObject(String dictObjectString, boolean parseName) {
    if (dictObjectString.isEmpty())
        return null;
    int pos = 0;
    int n = dictObjectString.length();
    String dictObjName = null;
    if (parseName) {
        if (Character.isUpperCase(dictObjectString.charAt(0)))
            pos++;
        else {
            newError("Incorrect dictionary object: " + dictObjectString, pos, "");
            return null;
        }
        while ((pos < n) && (Character.isLowerCase(dictObjectString.charAt(pos)) || Character.isDigit(dictObjectString.charAt(pos)) || dictObjectString.charAt(pos) == '_')) {
            pos++;
        }
        if (pos == n) {
            newError("Incorrecr dictionary object: " + dictObjectString, -1, "");
            return null;
        }
        dictObjName = dictObjectString.substring(0, pos);
        if (dictObjectString.charAt(pos) != ':') {
            newError("Incorrecr dictionary object: " + dictObjectString, -1, "");
            return null;
        } else
            pos++;
        if (pos == n) {
            newError("Incorrect dictionary object: " + dictObjectString, -1, "");
            return null;
        }
    }
    ParserState state = getState();
    errorContextPrefix = "Parsing macro/markush atom: " + dictObjectString + ": ";
    // Parsing a macro atom
    sln = dictObjectString.substring(pos);
    container = new SLNContainer(SilentChemObjectBuilder.getInstance());
    init();
    parse();
    ISLNDictionaryObject dictObj = null;
    if (errors.isEmpty()) {
        if (FlagUseSimpleMacroAtomsInDictionary && container.getAtomCount() == 1)
            dictObj = new AtomDictionaryObject(dictObjName, dictObjectString, container);
        else
            dictObj = new MacroAtomDictionaryObject(dictObjName, dictObjectString, container);
    }
    restoreState(state);
    errorContextPrefix = "";
    return dictObj;
}
Also used : MarkushAtomDictionaryObject(ambit2.sln.dictionary.MarkushAtomDictionaryObject) MacroAtomDictionaryObject(ambit2.sln.dictionary.MacroAtomDictionaryObject) AtomDictionaryObject(ambit2.sln.dictionary.AtomDictionaryObject) ISLNDictionaryObject(ambit2.sln.dictionary.ISLNDictionaryObject) MacroAtomDictionaryObject(ambit2.sln.dictionary.MacroAtomDictionaryObject)

Example 3 with MacroAtomDictionaryObject

use of ambit2.sln.dictionary.MacroAtomDictionaryObject in project ambit-mirror by ideaconsult.

the class Expander method expandDictionaryAtom.

public List<IAtom> expandDictionaryAtom(SLNAtom at) {
    // Handle a dictionary object
    if (at.dictObj instanceof AtomDictionaryObject) {
        AtomDictionaryObject aDO = (AtomDictionaryObject) at.dictObj;
        SLNAtom newAt = aDO.atom.clone();
        expContainer.addAtom(newAt);
        List<IAtom> list = new ArrayList<IAtom>();
        list.add(newAt);
        return list;
    } else if (at.dictObj instanceof MacroAtomDictionaryObject) {
        return expandMacroAtomDictionaryObject((MacroAtomDictionaryObject) at.dictObj);
    } else if (at.dictObj instanceof MarkushAtomDictionaryObject) {
        // Get the proper macro/atom component from the Markush atom
        // according to the markushPos[...] value
        // maObj is either AtomDictionaryObject or MacroAtomDictionaryObject
        ISLNDictionaryObject maObj = getProperDictionaryObject(at);
        if (maObj instanceof AtomDictionaryObject) {
            AtomDictionaryObject aDO = (AtomDictionaryObject) maObj;
            SLNAtom newAt = aDO.atom.clone();
            expContainer.addAtom(newAt);
            List<IAtom> list = new ArrayList<IAtom>();
            list.add(newAt);
            return list;
        } else {
            return expandMacroAtomDictionaryObject((MacroAtomDictionaryObject) maObj);
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) SLNAtom(ambit2.sln.SLNAtom) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

SLNAtom (ambit2.sln.SLNAtom)2 ArrayList (java.util.ArrayList)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 SLNBond (ambit2.sln.SLNBond)1 AtomDictionaryObject (ambit2.sln.dictionary.AtomDictionaryObject)1 ISLNDictionaryObject (ambit2.sln.dictionary.ISLNDictionaryObject)1 MacroAtomDictionaryObject (ambit2.sln.dictionary.MacroAtomDictionaryObject)1 MarkushAtomDictionaryObject (ambit2.sln.dictionary.MarkushAtomDictionaryObject)1