Search in sources :

Example 6 with IDCodeParser

use of com.actelion.research.chem.IDCodeParser in project openchemlib by Actelion.

the class ToxicityPredictor method getDetail.

public ParameterizedStringList getDetail(StereoMolecule testMolecule, int riskType) {
    ParameterizedStringList theDetail = new ParameterizedStringList();
    if (!sInitialized) {
        theDetail.add("Toxicity predictor not properly initialized.", ParameterizedStringList.cStringTypeText);
        return theDetail;
    }
    String idcode = new Canonizer(testMolecule).getIDCode();
    if (sRiskMolecules[riskType].contains(idcode)) {
        theDetail.add("This molecule is known to be " + cRiskNameA[riskType] + ":", ParameterizedStringList.cStringTypeText);
        theDetail.add(idcode, ParameterizedStringList.cStringTypeIDCode);
        return theDetail;
    }
    SSSearcher sss = new SSSearcher(SSSearcher.cMatchAtomCharge);
    boolean found = false;
    StereoMolecule fragment = new StereoMolecule();
    for (int i = 0; i < sHighRiskFragments[riskType].size(); i++) {
        new IDCodeParser(false).parse(fragment, sHighRiskFragments[riskType].get(i));
        sss.setMol(fragment, testMolecule);
        if (sss.isFragmentInMolecule()) {
            if (!found)
                theDetail.add("High-risk fragments indicating " + cRiskNameN[riskType] + ":", ParameterizedStringList.cStringTypeText);
            found = true;
            theDetail.add(sHighRiskFragments[riskType].get(i), ParameterizedStringList.cStringTypeIDCode);
        }
    }
    found = false;
    for (int i = 0; i < sLowRiskFragments[riskType].size(); i++) {
        new IDCodeParser(false).parse(fragment, sLowRiskFragments[riskType].get(i));
        sss.setMol(fragment, testMolecule);
        if (sss.isFragmentInMolecule()) {
            if (!found)
                theDetail.add("Medium-risk fragments indicating " + cRiskNameN[riskType] + ":", ParameterizedStringList.cStringTypeText);
            found = true;
            theDetail.add(sLowRiskFragments[riskType].get(i), ParameterizedStringList.cStringTypeIDCode);
        }
    }
    if (theDetail.getSize() == 0)
        theDetail.add("No indication for " + cRiskNameN[riskType] + " found.", ParameterizedStringList.cStringTypeText);
    return theDetail;
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) SSSearcher(com.actelion.research.chem.SSSearcher) StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Example 7 with IDCodeParser

use of com.actelion.research.chem.IDCodeParser in project openchemlib by Actelion.

the class ReactionEncoder method decode.

/**
 * Creates a Reaction object by interpreting a reaction code,
 * mapping, coordinates and drawing objects that were earlier created
 * by this class.
 * If rxnCoords are relative or null, and if ensureCoordinates==true
 * then all reactants and products are placed automatically along a
 * horizontal line.
 *
 * @return Reaction
 */
public static Reaction decode(String rxnCode, String rxnMapping, String rxnCoords, String rxnObjects, String rxnCatalysts, boolean ensureCoordinates) {
    if (rxnCode == null || rxnCode.length() == 0) {
        return null;
    }
    boolean isProduct = false;
    int idcodeIndex = 0;
    int mappingIndex = 0;
    int coordsIndex = 0;
    boolean reactionLayoutRequired = false;
    int productIndex = rxnCode.indexOf(PRODUCT_IDENTIFIER);
    if (productIndex == -1) {
        return null;
    }
    Reaction rxn = new Reaction();
    while (idcodeIndex != -1) {
        if (idcodeIndex > productIndex) {
            isProduct = true;
        }
        int delimiterIndex = rxnCode.indexOf(MOLECULE_DELIMITER, idcodeIndex);
        if (!isProduct && (delimiterIndex > productIndex || delimiterIndex == -1)) {
            delimiterIndex = productIndex;
        }
        String idcode = null;
        if (delimiterIndex == -1) {
            idcode = rxnCode.substring(idcodeIndex);
            idcodeIndex = -1;
        } else {
            idcode = rxnCode.substring(idcodeIndex, delimiterIndex);
            idcodeIndex = delimiterIndex + 1;
        }
        String mapping = null;
        if (rxnMapping != null && rxnMapping.length() != 0) {
            delimiterIndex = rxnMapping.indexOf(MOLECULE_DELIMITER, mappingIndex);
            if (delimiterIndex == -1) {
                mapping = rxnMapping.substring(mappingIndex);
            } else {
                mapping = rxnMapping.substring(mappingIndex, delimiterIndex);
                mappingIndex = delimiterIndex + 1;
            }
        }
        String coords = null;
        if (rxnCoords != null && rxnCoords.length() != 0) {
            delimiterIndex = rxnCoords.indexOf(MOLECULE_DELIMITER, coordsIndex);
            if (delimiterIndex == -1) {
                coords = rxnCoords.substring(coordsIndex);
            } else {
                coords = rxnCoords.substring(coordsIndex, delimiterIndex);
                coordsIndex = delimiterIndex + 1;
            }
        }
        IDCodeParser parser = new IDCodeParser(ensureCoordinates);
        StereoMolecule mol = parser.getCompactMolecule(idcode, coords);
        if (!reactionLayoutRequired && (coords == null || !parser.coordinatesAreAbsolute(coords)))
            reactionLayoutRequired = true;
        if (mapping != null) {
            parser.parseMapping(mapping.getBytes());
        }
        if (isProduct) {
            rxn.addProduct(mol);
        } else {
            rxn.addReactant(mol);
        }
    }
    if (rxnObjects != null && rxnObjects.length() != 0) {
        rxn.setDrawingObjects(new DrawingObjectList(rxnObjects));
    }
    if (rxnCatalysts != null && rxnCatalysts.length() != 0) {
        IDCodeParser parser = new IDCodeParser(ensureCoordinates);
        int index1 = 0;
        int index2 = rxnCatalysts.indexOf(CATALYST_DELIMITER);
        while (index2 != -1) {
            rxn.addCatalyst(parser.getCompactMolecule(rxnCatalysts.substring(index1, index2)));
            index1 = index2 + 1;
            index2 = rxnCatalysts.indexOf(CATALYST_DELIMITER, index1);
        }
        rxn.addCatalyst(parser.getCompactMolecule(rxnCatalysts.substring(index1)));
    }
    rxn.setReactionLayoutRequired(reactionLayoutRequired);
    return rxn;
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) DrawingObjectList(com.actelion.research.chem.DrawingObjectList) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 8 with IDCodeParser

use of com.actelion.research.chem.IDCodeParser in project openchemlib by Actelion.

the class HoseCodeCreator method main.

public static void main(String[] args) {
    StereoMolecule molecule = new IDCodeParser(false).getCompactMolecule("deT@@DjU_k``b`@@");
    StereoMolecule otherMolecule = new StereoMolecule(molecule.getAtoms(), molecule.getBonds());
    boolean[] atomMask = new boolean[molecule.getAtoms()];
    Arrays.fill(atomMask, true);
    molecule.copyMoleculeByAtoms(otherMolecule, atomMask, true, null);
    System.out.println(new Canonizer(otherMolecule, Canonizer.ENCODE_ATOM_CUSTOM_LABELS).getIDCode());
    // String id="deT@`@f\bbbRK]@PT@@";
    String id = "fi{qa@DyZkQPSI`cHhhdhdhddhekF\\\\fNXBBjfjjjaXTh@RB@QJh";
    String[] hoses = HoseCodeCreator.getHoseCodesFromDiaID(id, 20, FULL_HOSE_CODE);
    for (int i = 0; i < hoses.length; i++) {
        System.out.println(hoses[i]);
    }
    hoses = HoseCodeCreator.getHoseCodesFromDiaID(id, 8, HOSE_CODE_CUT_C_SP3_SP3);
    for (int i = 0; i < hoses.length; i++) {
        System.out.println(hoses[i]);
    }
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Aggregations

IDCodeParser (com.actelion.research.chem.IDCodeParser)8 StereoMolecule (com.actelion.research.chem.StereoMolecule)8 SSSearcher (com.actelion.research.chem.SSSearcher)4 Canonizer (com.actelion.research.chem.Canonizer)3 DrawingObjectList (com.actelion.research.chem.DrawingObjectList)1 ArrayList (java.util.ArrayList)1