Search in sources :

Example 6 with SLNAtom

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

the class SLN2ChemObject method slnContainerToAtomContainer.

public IAtomContainer slnContainerToAtomContainer(SLNContainer slnContainer) {
    clearAllErrorsAndWarnings();
    IAtomContainer container = new AtomContainer();
    Map<SLNAtom, IAtom> convertedAtoms = new HashMap<SLNAtom, IAtom>();
    for (int i = 0; i < slnContainer.getAtomCount(); i++) {
        SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
        IAtom atom = slnAtomToAtom(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);
        IBond bond = slnBondToBond(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);
    }
    try {
        processMolecule(container);
    } catch (Exception x) {
        conversionErrors.add(x.getMessage());
    }
    return container;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) HashMap(java.util.HashMap) SLNBond(ambit2.sln.SLNBond) IBond(org.openscience.cdk.interfaces.IBond) SLNAtom(ambit2.sln.SLNAtom) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 7 with SLNAtom

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

the class Expander method handleBond.

public void handleBond(IBond bond) {
    SLNBond bo = (SLNBond) bond;
    SLNBond newBo = bo.clone();
    IAtom at0 = bo.getAtom(0);
    IAtom at1 = bo.getAtom(1);
    int conectionInd0 = getConnectionIndexOfTheBond(bond, at0);
    int conectionInd1 = getConnectionIndexOfTheBond(bond, at1);
    // TODO improved valencePos index handling taking into account attribute v if present
    int valencePos0Index = conectionInd0;
    int valencePos1Index = conectionInd1;
    Object newObj0 = oldToNewAtoms.get(at0);
    Object newObj1 = oldToNewAtoms.get(at1);
    IAtom newAt0 = getNewAtomWhichIsValenceConection(valencePos0Index, newObj0, (SLNAtom) at0);
    IAtom newAt1 = getNewAtomWhichIsValenceConection(valencePos1Index, newObj1, (SLNAtom) at1);
    newBo.setAtoms(new IAtom[] { newAt0, newAt1 });
    expContainer.addBond(newBo);
}
Also used : SLNBond(ambit2.sln.SLNBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 8 with SLNAtom

use of ambit2.sln.SLNAtom 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 9 with SLNAtom

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

the class SLNHelper method nodeToString.

String nodeToString(IAtom atom) {
    // System.out.println("-->nodeToString for atom: " + curSLNContainer.getAtomNumber(atom));
    StringBuffer sb = new StringBuffer();
    TopLayer afs = firstSphere.get(atom);
    AtomSLNNode curNode = nodes.get(atom);
    List<String> branches = new ArrayList<String>();
    List<String> closureStrings = new ArrayList<String>();
    for (int i = 0; i < afs.atoms.size(); i++) {
        IAtom neighborAt = afs.atoms.get(i);
        if (neighborAt == curNode.parent)
            continue;
        AtomSLNNode neighborNode = nodes.get(neighborAt);
        if (// This node has not been registered yet
        neighborNode == null) {
            // Registering a new Node and a new branch
            AtomSLNNode newNode = new AtomSLNNode();
            newNode.atom = neighborAt;
            newNode.parent = atom;
            nodes.put(newNode.atom, newNode);
            String bond_str = afs.bonds.get(i).toString();
            String newBranch = bond_str + nodeToString(neighborAt);
            branches.add(newBranch);
        } else {
            IBond neighborBo = afs.bonds.get(i);
            // This check is needed. Otherwise the ring closure will be described twice (for both atoms of the bond)
            if (ringClosures.contains(neighborBo))
                continue;
            ringClosures.add(neighborBo);
            // Handle a new ring closure
            // Set the ID of the first atom from the ring closure
            // Because of the recursion approach the atoms are not yet added converted to strings
            int neighID = ((SLNAtom) neighborAt).atomID;
            if (// The neighbor atom does not have ID
            neighID == -1) {
                // A new atom ID is generated
                maxAtomID++;
                neighID = maxAtomID;
                setAtomID((SLNAtom) neighborAt, neighID);
            }
            String newClosure = afs.bonds.get(i).toString() + "@" + neighID;
            closureStrings.add(newClosure);
        // System.out.println("  #add ring closure: atom " + curSLNContainer.getAtomNumber(atom) + " to atom "
        // + curSLNContainer.getAtomNumber(neighborAt) + " with ID " + neighID);
        }
    }
    // Add atom from the current node
    sb.append(atom.toString());
    // Add ring closures
    for (int i = 0; i < closureStrings.size(); i++) sb.append(closureStrings.get(i));
    // Add branches
    if (branches.size() > 0) {
        for (int i = 0; i < branches.size() - 1; i++) sb.append("(" + branches.get(i).toString() + ")");
        sb.append(branches.get(branches.size() - 1).toString());
    }
    return (sb.toString());
}
Also used : ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) TopLayer(ambit2.smarts.TopLayer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 10 with SLNAtom

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

the class SLN2ChemObject method slnAtomToAtom.

public IAtom slnAtomToAtom(SLNAtom slnAt) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (slnAt == null) {
        currentConversionError = "SNLAtom is null";
        return null;
    }
    if ((slnAt.atomType > 0) && (slnAt.atomType < SLNConst.GlobalDictOffseet)) {
        if (slnAt.atomType < SLNConst.elSymbols.length) {
            IAtom atom = new Atom();
            atom.setSymbol(SLNConst.elSymbols[slnAt.atomType]);
            atom.setAtomicNumber(PeriodicTable.getAtomicNumber(SLNConst.elSymbols[slnAt.atomType]));
            atom.setImplicitHydrogenCount(slnAt.numHAtom);
            if (slnAt.atomExpression != null) {
                Integer charge = extractFormalCharge(slnAt.atomExpression);
                if (charge != null)
                    if (charge != 0)
                        atom.setFormalCharge(charge);
            // TODO isotope
            }
            return atom;
        } else {
            currentConversionError = "SNLAtom type is incorrect: " + slnAt.atomType;
            return null;
        }
    } else {
        currentConversionError = "SNLAtom type is not defined";
        return null;
    }
}
Also used : IAtom(org.openscience.cdk.interfaces.IAtom) AromaticSymbolQueryAtom(ambit2.smarts.AromaticSymbolQueryAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) SLNAtom(ambit2.sln.SLNAtom) AliphaticSymbolQueryAtom(ambit2.smarts.AliphaticSymbolQueryAtom) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) IAtom(org.openscience.cdk.interfaces.IAtom) SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) AliphaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom) AromaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom) Atom(org.openscience.cdk.Atom)

Aggregations

SLNAtom (ambit2.sln.SLNAtom)10 IAtom (org.openscience.cdk.interfaces.IAtom)9 SLNBond (ambit2.sln.SLNBond)5 SLNContainer (ambit2.sln.SLNContainer)3 SmartsAtomExpression (ambit2.smarts.SmartsAtomExpression)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IBond (org.openscience.cdk.interfaces.IBond)3 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)3 AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)3 AliphaticSymbolQueryAtom (ambit2.smarts.AliphaticSymbolQueryAtom)2 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)2 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)2 SLNExpressionToken (ambit2.sln.SLNExpressionToken)1 ISLNDictionaryObject (ambit2.sln.dictionary.ISLNDictionaryObject)1 AromaticSymbolQueryAtom (ambit2.smarts.AromaticSymbolQueryAtom)1 SmartsExpressionToken (ambit2.smarts.SmartsExpressionToken)1 TopLayer (ambit2.smarts.TopLayer)1 Atom (org.openscience.cdk.Atom)1 AtomContainer (org.openscience.cdk.AtomContainer)1