Search in sources :

Example 1 with SmartsAtomExpression

use of ambit2.smarts.SmartsAtomExpression 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 2 with SmartsAtomExpression

use of ambit2.smarts.SmartsAtomExpression 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)

Example 3 with SmartsAtomExpression

use of ambit2.smarts.SmartsAtomExpression in project ambit-mirror by ideaconsult.

the class TestUtilities method testStereoFromSmartsAtomExpression.

int testStereoFromSmartsAtomExpression(String smarts) throws Exception {
    System.out.println("Stereo chirality for: " + smarts);
    IQueryAtomContainer query = sp.parse(smarts);
    String errorMsg = sp.getErrorMessages();
    if (!errorMsg.equals("")) {
        System.out.println(errorMsg);
        return (-1);
    }
    for (int i = 0; i < query.getAtomCount(); i++) {
        IAtom at = query.getAtom(i);
        if (at instanceof SmartsAtomExpression) {
            SmartsAtomExpression smae = (SmartsAtomExpression) at;
            int chir = StereoFromSmartsAtomExpression.getStereo(smae);
            System.out.println("atom #" + (i + 1) + "  " + smae.toString() + "  -->" + chiralityToString(chir));
        }
    }
    return 0;
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom) StereoFromSmartsAtomExpression(ambit2.smarts.StereoFromSmartsAtomExpression) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Example 4 with SmartsAtomExpression

use of ambit2.smarts.SmartsAtomExpression in project ambit-mirror by ideaconsult.

the class TestUtilities method testStereoRemovedTokens.

public void testStereoRemovedTokens(String smarts) {
    System.out.println("Smarts " + smarts);
    IQueryAtomContainer qac = sp.parse(smarts);
    if (!sp.getErrorMessages().equals("")) {
        System.out.println("Smarts Parser errors:\n" + sp.getErrorMessages());
        return;
    }
    // System.out.println("Atoms: " + SmartsHelper.getAtomsString(qac));
    SmartsAtomExpression expr = (SmartsAtomExpression) qac.getAtom(0);
    expr.getStereoRemovedTokens();
    System.out.println(expr.toString());
    System.out.println(expr.stereoRemovedToString());
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) StereoFromSmartsAtomExpression(ambit2.smarts.StereoFromSmartsAtomExpression) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Example 5 with SmartsAtomExpression

use of ambit2.smarts.SmartsAtomExpression in project ambit-mirror by ideaconsult.

the class TestUtilities method testHAtomsManager.

int testHAtomsManager(String smarts) throws Exception {
    System.out.println("H atoms for: " + smarts);
    IQueryAtomContainer query = sp.parse(smarts);
    String errorMsg = sp.getErrorMessages();
    if (!errorMsg.equals("")) {
        System.out.println(errorMsg);
        return (-1);
    }
    for (int i = 0; i < query.getAtomCount(); i++) {
        IAtom at = query.getAtom(i);
        if (at instanceof SmartsAtomExpression) {
            SmartsAtomExpression smae = (SmartsAtomExpression) at;
            int ha = HAtomManager.getHAtoms(smae);
            System.out.println("atom #" + (i + 1) + "  " + smae.toString() + "  --> " + ha);
        }
    }
    return 0;
}
Also used : IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom) StereoFromSmartsAtomExpression(ambit2.smarts.StereoFromSmartsAtomExpression) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Aggregations

SmartsAtomExpression (ambit2.smarts.SmartsAtomExpression)6 SmartsExpressionToken (ambit2.smarts.SmartsExpressionToken)3 StereoFromSmartsAtomExpression (ambit2.smarts.StereoFromSmartsAtomExpression)3 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)3 IAtom (org.openscience.cdk.interfaces.IAtom)2 AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)2 SLNAtom (ambit2.sln.SLNAtom)1 SLNExpressionToken (ambit2.sln.SLNExpressionToken)1 AliphaticSymbolQueryAtom (ambit2.smarts.AliphaticSymbolQueryAtom)1