Search in sources :

Example 1 with SmartsExpressionToken

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

the class SmartsMatch method exactMatch.

boolean exactMatch(SmartsAtomExpression qa, SmartsAtomExpression ta) {
    if (qa.tokens.size() != ta.tokens.size())
        return false;
    for (int i = 0; i < qa.tokens.size(); i++) {
        SmartsExpressionToken qaTok = qa.tokens.get(i);
        SmartsExpressionToken taTok = ta.tokens.get(i);
        if (qaTok.type != taTok.type)
            return false;
        if (qaTok.param != taTok.param)
            return false;
    }
    return true;
}
Also used : SmartsExpressionToken(ambit2.smarts.SmartsExpressionToken)

Example 2 with SmartsExpressionToken

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

the class HAtomManager method getExpressionHAtoms.

static int getExpressionHAtoms(SmartsAtomExpression atExp, SmartsAtomExpression sub) {
    // 'sub' expression is represented only by HI_AND and NOT operations
    // Getting the positions of HI_AND tokens
    int[] pos = new int[sub.tokens.size() + 2];
    pos[0] = -1;
    int n = 0;
    for (int i = 0; i < sub.tokens.size(); i++) {
        if (sub.tokens.get(i).type == SmartsConst.LO + SmartsConst.LO_AND) {
            n++;
            pos[n] = i;
        }
    }
    n++;
    pos[n] = sub.tokens.size();
    int expHAtoms = -1;
    boolean FlagNot;
    SmartsExpressionToken seTok;
    // ends of the token sequence
    for (int i = 1; i <= n; i++) {
        // Handling the tokens between pos[i-1] and pos[i]
        FlagNot = false;
        for (int k = pos[i - 1] + 1; k < pos[i]; k++) {
            seTok = sub.tokens.get(k);
            if (seTok.isLogicalOperation()) {
                if (seTok.getLogOperation() == SmartsConst.LO_NOT)
                    FlagNot = !FlagNot;
                if (seTok.getLogOperation() == SmartsConst.LO_AND)
                    // 'Not' flag is reseted
                    FlagNot = false;
                continue;
            }
            // (if there is contradiction this smarts expression will not be matched anyway)
            switch(seTok.type) {
                case SmartsConst.AP_H:
                    if (seTok.param >= 0)
                        if (!FlagNot)
                            expHAtoms = seTok.param;
                    break;
                case SmartsConst.AP_Recursive:
                    int ha = getRecursiveExpressionHAtoms(atExp, seTok.param);
                    // return -2;  ???
                    if (ha >= 0)
                        if (!FlagNot)
                            expHAtoms = ha;
                    break;
            }
        }
    }
    return (expHAtoms);
}
Also used : SmartsExpressionToken(ambit2.smarts.SmartsExpressionToken)

Example 3 with SmartsExpressionToken

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

the class SLN2ChemObject method slnExpressionTokenToSmartsExpressionTokenArray.

public SmartsExpressionToken[] slnExpressionTokenToSmartsExpressionTokenArray(SLNExpressionToken slnTok) {
    // -1 do not convert, 0 convert as equal, 1 generate list of alternative values
    int conversionStatus = 0;
    String warning = null;
    // Determine conversionStatus
    switch(slnTok.comparisonOperation) {
        case SLNConst.CO_EQUALS:
            conversionStatus = 0;
            break;
        case SLNConst.CO_LESS_THAN:
        case SLNConst.CO_GREATER_THAN:
            switch(conversionConfig.FlagComparisonConversion) {
                case omit:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_equal:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_equal_if_equal_is_present:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_equal_if_not_nonequality:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_value_list:
                    conversionStatus = 1;
                    warning = "logical primitive converted as value list";
                    break;
            }
            break;
        case SLNConst.CO_LESS_OR_EQUALS:
        case SLNConst.CO_GREATER_OR_EQUALS:
            switch(conversionConfig.FlagComparisonConversion) {
                case omit:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_equal:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_equal_if_equal_is_present:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_equal_if_not_nonequality:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_value_list:
                    conversionStatus = 1;
                    warning = "logical primitive converted as value list";
                    break;
            }
            break;
        case SLNConst.CO_DIFFERS:
            switch(conversionConfig.FlagComparisonConversion) {
                case omit:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_equal:
                    conversionStatus = 0;
                    warning = "logical primitive converted as equal comparison";
                    break;
                case convert_as_equal_if_equal_is_present:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_equal_if_not_nonequality:
                    conversionStatus = -1;
                    warning = "logical primitive is not converted";
                    break;
                case convert_as_value_list:
                    conversionStatus = 1;
                    warning = "logical primitive converted as value list";
                    break;
            }
            break;
    }
    if (warning != null)
        addToCurrentConversionWarning(slnTok.toString(true) + "  " + warning);
    if (conversionStatus < 0)
        return null;
    else if (conversionStatus == 0) {
        SmartsExpressionToken tok = slnExpressionTokenToSmartsExpressionToken(slnTok);
        if (tok != null)
            return new SmartsExpressionToken[] { tok };
    } else {
        // Generate an array of tokens based on the alternative values;
        int[] altValues = getSmartsTokenAlternativeValues(slnTok);
        if (altValues == null || altValues.length == 0) {
            addToCurrentConversionWarning(slnTok.toString(true) + " Error on creating alternative values list.");
            return null;
        }
        SmartsExpressionToken[] altTokens = new SmartsExpressionToken[altValues.length + altValues.length - 1];
        for (int i = 0; i < altValues.length; i++) {
            // System.out.println("alt value --> " + altValues[i]);
            SmartsExpressionToken tok = getAlternativeSmartsToken(slnTok, altValues[i]);
            altTokens[2 * i] = tok;
            if (i > 0)
                altTokens[2 * i - 1] = new SmartsExpressionToken(SmartsConst.LO + SmartsConst.LO_ANDLO, 0);
        }
        return altTokens;
    }
    return null;
}
Also used : SmartsExpressionToken(ambit2.smarts.SmartsExpressionToken)

Example 4 with SmartsExpressionToken

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

the class SLN2ChemObject method slnAtomToSmartsAtomExpression.

public SmartsAtomExpression slnAtomToSmartsAtomExpression(SLNAtom slnAt) {
    SmartsAtomExpression atExpr = new SmartsAtomExpression(SilentChemObjectBuilder.getInstance());
    // Adding atom name
    if (slnAt.atomType == 0) {
        atExpr.tokens.add(new SmartsExpressionToken(SmartsConst.AP_ANY, 0));
    } else {
        if (slnAt.atomType < SLNConst.elSymbols.length)
            atExpr.tokens.add(new SmartsExpressionToken(SmartsConst.AP_A, slnAt.atomType));
        else {
        // Handle dictionary info
        }
    }
    // Adding implicit H atoms from the name
    if (slnAt.numHAtom > 0) {
        // Insert logical operation AND_LO
        atExpr.tokens.add(new SmartsExpressionToken(SmartsConst.LO + SmartsConst.LO_ANDLO, 0));
        atExpr.tokens.add(new SmartsExpressionToken(SmartsConst.AP_H, slnAt.numHAtom));
    }
    if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty())
        return atExpr;
    // Insert logical operation AND_LO
    atExpr.tokens.add(new SmartsExpressionToken(SmartsConst.LO + SmartsConst.LO_ANDLO, 0));
    // Converting SLN atom expression into SMARTS atom expression
    for (int i = 0; i < slnAt.atomExpression.tokens.size(); i++) {
        SLNExpressionToken slnTok = slnAt.atomExpression.tokens.get(i);
        if (slnTok.isLogicalOperation()) {
            SmartsExpressionToken logOpTok = slnLogOperationToSmartsExpressionToken(slnTok.getLogOperation());
            atExpr.tokens.add(logOpTok);
        } else {
            SmartsExpressionToken[] smToks = slnExpressionTokenToSmartsExpressionTokenArray(slnTok);
            if (smToks != null) {
                for (int k = 0; k < smToks.length; k++) atExpr.tokens.add(smToks[k]);
            } else {
                // Check for preceding NOT
                if (!atExpr.tokens.isEmpty()) {
                    int n = atExpr.tokens.size();
                    SmartsExpressionToken tok = atExpr.tokens.get(n - 1);
                    if (tok.type == SmartsConst.LO + SmartsConst.LO_NOT)
                        atExpr.tokens.remove(n - 1);
                }
                // TODO Improve: check for the type of LO
                if (!atExpr.tokens.isEmpty()) {
                    int n = atExpr.tokens.size();
                    SmartsExpressionToken tok = atExpr.tokens.get(n - 1);
                    if (tok.isLogicalOperation())
                        atExpr.tokens.remove(n - 1);
                }
            }
        }
    }
    return atExpr;
}
Also used : SmartsExpressionToken(ambit2.smarts.SmartsExpressionToken) SLNExpressionToken(ambit2.sln.SLNExpressionToken) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Aggregations

SmartsExpressionToken (ambit2.smarts.SmartsExpressionToken)4 SLNExpressionToken (ambit2.sln.SLNExpressionToken)1 SmartsAtomExpression (ambit2.smarts.SmartsAtomExpression)1