Search in sources :

Example 1 with ICondition

use of ambit2.rules.conditions.ICondition in project ambit-mirror by ideaconsult.

the class GenericReaction method getReactionFromJsonNode.

public static GenericReaction getReactionFromJsonNode(JsonNode node) throws Exception {
    GenericReaction reaction = new GenericReaction();
    Boolean use = JSONParsingUtils.extractBooleanKeyword(node, "USE", false);
    if (use != null)
        reaction.setFlagUse(use);
    reaction.name = JSONParsingUtils.extractStringKeyword(node, "NAME", true);
    reaction.smirks = JSONParsingUtils.extractStringKeyword(node, "SMIRKS", true);
    reaction.reactionClass = JSONParsingUtils.extractStringKeyword(node, "CLASS", false);
    Object[] obj = JSONParsingUtils.extractArrayKeyword(node, "USE_CONDITIONS", false, true);
    if (obj != null) {
        List<ICondition> conditions = new ArrayList<ICondition>();
        for (int i = 0; i < obj.length; i++) {
            if (obj[i] == null)
                continue;
            if (obj[i] instanceof String) {
                ICondition condition = ReactionParser.getConditionFromString((String) obj[i]);
                conditions.add(condition);
            } else {
                if (obj[i] instanceof JsonNode) {
                    IDescriptorValueCondition dvc = ConditionJsonParser.getDescriptorValueCondition((JsonNode) obj[i]);
                    conditions.add(dvc);
                } else
                    throw new Exception("Incorrect USE_CONDITIONS[" + (i + 1) + "]. It is not a string! " + obj[i]);
            }
        }
        reaction.setConditions(conditions);
    }
    return reaction;
}
Also used : IDescriptorValueCondition(ambit2.rules.conditions.IDescriptorValueCondition) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ICondition(ambit2.rules.conditions.ICondition) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException)

Example 2 with ICondition

use of ambit2.rules.conditions.ICondition in project ambit-mirror by ideaconsult.

the class GenericReactionInstance method calculateConditionsStatus.

public void calculateConditionsStatus() {
    if (reaction == null)
        return;
    if (reaction.conditions != null) {
        int n = reaction.conditions.size();
        conditionsStatus = new boolean[n];
        for (int i = 0; i < n; i++) {
            ICondition cond = reaction.conditions.get(i);
            conditionsStatus[i] = cond.isTrue(this);
        }
    }
    if (reaction.applicationConditions != null) {
        int n = reaction.applicationConditions.size();
        applicationConditionsStatus = new boolean[n];
        for (int i = 0; i < n; i++) {
            ICondition cond = reaction.applicationConditions.get(i);
            applicationConditionsStatus[i] = cond.isTrue(this);
        }
    }
}
Also used : ICondition(ambit2.rules.conditions.ICondition)

Aggregations

ICondition (ambit2.rules.conditions.ICondition)2 EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)1 IDescriptorValueCondition (ambit2.rules.conditions.IDescriptorValueCondition)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1