Search in sources :

Example 1 with SLNAtom

use of ambit2.sln.SLNAtom 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;
}
Also used : HashMap(java.util.HashMap) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with SLNAtom

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

the class SLN2ChemObject method atomContainerToSLNContainer.

public SLNContainer atomContainerToSLNContainer(IAtomContainer container) {
    clearAllErrorsAndWarnings();
    SLNContainer slnContainer = new SLNContainer(null);
    Map<IAtom, SLNAtom> convertedAtoms = new HashMap<IAtom, SLNAtom>();
    for (int i = 0; i < container.getAtomCount(); i++) {
        IAtom atom = container.getAtom(i);
        SLNAtom slnAtom = atomToSLNAtom(atom);
        if (currentConversionWarning != null)
            conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
        if (slnAtom == null) {
            conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
            continue;
        }
        slnContainer.addAtom(slnAtom);
        convertedAtoms.put(atom, slnAtom);
    }
    for (int i = 0; i < container.getBondCount(); i++) {
        IBond bond = container.getBond(i);
        SLNBond slnBond = bondToSLNBond(bond);
        if (currentConversionWarning != null)
            conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
        if (slnBond == null) {
            conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
            continue;
        }
        SLNAtom[] newAtoms = new SLNAtom[2];
        newAtoms[0] = convertedAtoms.get(bond.getAtom(0));
        newAtoms[1] = convertedAtoms.get(bond.getAtom(1));
        if (newAtoms[0] == null || newAtoms[1] == null) {
            conversionErrors.add("One of the atoms for bond: " + (i + 1) + " is not converted");
            // one of the atoms is not converted
            continue;
        }
        slnBond.setAtoms(newAtoms);
        slnContainer.addBond(slnBond);
    }
    return slnContainer;
}
Also used : HashMap(java.util.HashMap) IBond(org.openscience.cdk.interfaces.IBond) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) SLNContainer(ambit2.sln.SLNContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with SLNAtom

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

the class SLN2ChemObject method atomToSLNAtom.

public SLNAtom atomToSLNAtom(IAtom atom) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (atom == null) {
        currentConversionError = "Atom is null";
        return null;
    }
    SLNAtom slnAt = new SLNAtom(builder);
    String atomName = atom.getSymbol();
    for (int i = 0; i < SLNConst.elSymbols.length; i++) if (atomName.equals(SLNConst.elSymbols[i])) {
        slnAt.atomType = i;
        break;
    }
    slnAt.atomName = atomName;
    if (atom.getImplicitHydrogenCount() != null)
        slnAt.numHAtom = atom.getImplicitHydrogenCount();
    return slnAt;
}
Also used : SLNAtom(ambit2.sln.SLNAtom)

Example 4 with SLNAtom

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

the class SLN2ChemObject method slnAtomToQueryAtom.

public IQueryAtom slnAtomToQueryAtom(SLNAtom slnAt) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (slnAt == null) {
        currentConversionError = "SNLAtom is null";
        return null;
    }
    if (slnAt.atomType == 0) {
        if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
            if (slnAt.numHAtom == 0)
                return new AnyAtom(SilentChemObjectBuilder.getInstance());
        }
        // Handle Any atom as an expression
        // slnAt.numHAtom > 0 info is added into the expression
        SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
        return atExpr;
    }
    // slnAt.atomType > 0
    if (slnAt.atomType < SLNConst.GlobalDictOffseet) {
        if (slnAt.atomType < SLNConst.elSymbols.length) {
            if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
                if (slnAt.numHAtom == 0) {
                    AliphaticSymbolQueryAtom atom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
                    String symb = SLNConst.elSymbols[slnAt.atomType];
                    atom.setSymbol(symb);
                    atom.setAtomicNumber(PeriodicTable.getAtomicNumber(symb));
                    return atom;
                } else {
                // Since there are H atoms they define an expression
                // slnAt.numHAtom > 0 info is added into the expression
                }
            }
            // Create an expression
            SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
            return atExpr;
        } else {
            // TODO
            return null;
        }
    } else {
        // TODO
        return null;
    }
}
Also used : AliphaticSymbolQueryAtom(ambit2.smarts.AliphaticSymbolQueryAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Example 5 with SLNAtom

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

the class SLN2ChemObject method queryAtomToSLNAtom.

public SLNAtom queryAtomToSLNAtom(IQueryAtom queryAtom) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (queryAtom == null) {
        currentConversionError = "Atom is null";
        return null;
    }
    if (queryAtom instanceof SmartsAtomExpression) {
    // TODO
    }
    boolean FlagKnownAtomType = false;
    SLNAtom slnAt = new SLNAtom(builder);
    if (queryAtom instanceof AnyAtom) {
        slnAt.atomType = 0;
        slnAt.atomName = "Any";
        FlagKnownAtomType = true;
    }
    if (FlagKnownAtomType)
        return slnAt;
    else
        return null;
/*
         * SLNAtom slnAt = new SLNAtom(builder);		
			String atomName = atom.getSymbol();
			for (int i = 0; i < SLNConst.elSymbols.length; i++)
			if (atomName.equals(SLNConst.elSymbols[i]))
			{	
				slnAt.atomType = i;
				break;
			}	
		    slnAt.atomName = atomName;         
         
		if (a instanceof AliphaticSymbolQueryAtom)
			return (a.getSymbol());

		if (a instanceof AromaticSymbolQueryAtom)
			return (a.getSymbol().toLowerCase());

		if (a instanceof AliphaticAtom)
			return ("A");

		if (a instanceof AromaticAtom)
			return ("a");		
         */
}
Also used : SLNAtom(ambit2.sln.SLNAtom) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)

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