use of ambit2.sln.SLNExpressionToken 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;
}
use of ambit2.sln.SLNExpressionToken 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;
}
Aggregations