Search in sources :

Example 1 with EmptyMoleculeException

use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.

the class FingerprintGenerator method process.

public BitSet process(IAtomContainer object) throws AmbitException {
    try {
        if ((object == null) || (object.getAtomCount() == 0))
            throw new EmptyMoleculeException();
        long fp_time = System.currentTimeMillis();
        IAtomContainer c = object;
        if (hydrogens) {
            if (hAdder == null)
                hAdder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
            c = object.clone();
            hAdder.addImplicitHydrogens(c);
            MoleculeTools.convertImplicitToExplicitHydrogens(c);
        } else {
            if (object.getBondCount() > 1) {
                for (IAtom atom : object.atoms()) if (atom.getImplicitHydrogenCount() == null) {
                    if ("H".equals(atom.getSymbol()))
                        atom.setImplicitHydrogenCount(0);
                }
                c = AtomContainerManipulator.copyAndSuppressedHydrogens(object);
            } else
                c = object;
        }
        fp_time = System.currentTimeMillis() - fp_time;
        object.setProperty(AmbitCONSTANTS.FingerprintTIME, new Long(fp_time));
        return fingerprinter.getBitFingerprint(c).asBitSet();
    } catch (AmbitException x) {
        throw x;
    } catch (Exception x) {
        throw new AmbitException("Error generating fingerprint\t" + x.getMessage(), x);
    }
}
Also used : EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with EmptyMoleculeException

use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.

the class HNMRShifts method findAllHAtomEnvironmentInstances.

void findAllHAtomEnvironmentInstances() throws EmptyMoleculeException {
    for (int i = 0; i < knowledgeBase.hAtomEnvironments.size(); i++) {
        HAtomEnvironment hae = knowledgeBase.hAtomEnvironments.get(i);
        if (!hae.flagUse)
            continue;
        List<List<IAtom>> atMaps = hae.groupMatch.getMappings(molecule);
        if (atMaps.isEmpty())
            continue;
        for (int k = 0; k < atMaps.size(); k++) {
            HAtomEnvironmentInstance haeInst = new HAtomEnvironmentInstance();
            haeInst.hEnvironment = hae;
            int n = atMaps.get(k).size();
            haeInst.atoms = new IAtom[n];
            for (int r = 0; r < n; r++) haeInst.atoms[r] = atMaps.get(k).get(r);
            hAtEnvInstances.add(haeInst);
            registerHAtomEnvironmentInstance(haeInst);
        }
    }
}
Also used : HAtomEnvironment(ambit2.groupcontribution.nmr.nmr_1h.HAtomEnvironment) ArrayList(java.util.ArrayList) List(java.util.List) HAtomEnvironmentInstance(ambit2.groupcontribution.nmr.nmr_1h.HAtomEnvironmentInstance)

Example 3 with EmptyMoleculeException

use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.

the class RetroSynthesis method findRuleInstances.

ArrayList<IRetroSynthRuleInstance> findRuleInstances(IAtomContainer str, RetroSynthRule rule) throws EmptyMoleculeException {
    ArrayList<IRetroSynthRuleInstance> instances = new ArrayList<IRetroSynthRuleInstance>();
    smrkMan.getIsomorphismTester().setQuery(rule.reaction.reactant);
    SmartsParser.prepareTargetForSMARTSSearch(rule.reaction.reactantFlags, str);
    List<List<IAtom>> rMaps = smrkMan.getNonOverlappingMappings(str);
    for (int i = 0; i < rMaps.size(); i++) {
        RetroSynthRuleInstance rInstance = new RetroSynthRuleInstance();
        rInstance.setAtoms(rMaps.get(i));
        rInstance.setRule(rule);
        instances.add(rInstance);
        System.out.print("rule: " + rule.smirks + "  ");
        smrkMan.printSSMap(str, rInstance.getAtoms());
    }
    return instances;
}
Also used : IRetroSynthRuleInstance(ambit2.reactions.rules.IRetroSynthRuleInstance) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RetroSynthRuleInstance(ambit2.reactions.rules.RetroSynthRuleInstance) IRetroSynthRuleInstance(ambit2.reactions.rules.IRetroSynthRuleInstance)

Example 4 with EmptyMoleculeException

use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.

the class AutomaticTestUtilities method calcBitVectorStrings.

public int calcBitVectorStrings() throws EmptyMoleculeException {
    // Input file is interpreted as str. keys set
    // for each DB structure BitVector is calculated and saved to the output
    // file
    // Loading the structure keys
    Vector<String> externKeySet = new Vector<String>();
    try {
        File file = new File(inFileName);
        RandomAccessFile f = new RandomAccessFile(file, "r");
        String line;
        long length = f.length();
        while (f.getFilePointer() < length) {
            line = f.readLine();
            String smiles = line.trim();
            if (!smiles.equals(""))
                externKeySet.add(smiles);
        }
        f.close();
    } catch (Exception e) {
        System.out.println("Probleb with the input file:");
        e.printStackTrace();
        return (-1);
    }
    Screening screen = new Screening(externKeySet);
    if (dbFileName.endsWith(".txt") || dbFileName.endsWith(".smi")) {
        try {
            File file = new File(dbFileName);
            RandomAccessFile f = new RandomAccessFile(file, "r");
            String line;
            long length = f.length();
            int record = 0;
            while (f.getFilePointer() < length) {
                line = f.readLine();
                String smiles = line.trim();
                IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles);
                BitSet bs = screen.getStructureKeyBits(mol);
                String s = screen.getBitSetString(bs);
                output(s + endLine);
                record++;
                if (record % 100 == 0)
                    System.out.println("rec " + record);
            }
            f.close();
        } catch (Exception e) {
            System.out.println("Probleb with the SMILES DB file :");
            e.printStackTrace();
            return (-1);
        }
        return (0);
    }
    try {
        IChemObjectBuilder b = SilentChemObjectBuilder.getInstance();
        IteratingSDFReader reader = new IteratingSDFReader(new FileReader(dbFileName), b);
        int record = 0;
        int readComp = 0;
        while (reader.hasNext()) {
            record++;
            if (record > this.nDBStr)
                break;
            if ((record % 100) == 0)
                System.out.println("rec " + record + "   (" + readComp + ")");
            Object o = reader.next();
            if (o instanceof IAtomContainer) {
                readComp++;
                IAtomContainer mol = (IAtomContainer) o;
                if (mol.getAtomCount() == 0)
                    continue;
                AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
                CDKHueckelAromaticityDetector.detectAromaticity(mol);
                BitSet bs = screen.getStructureKeyBits(mol);
                String s = screen.getBitSetString(bs);
                output(s + endLine);
            // Test
            // BitSet bs2 = screen.stringToBitSet(s);
            // String s2 = screen.getBitSetString(bs2);
            // System.out.println(s + "   " + s2);
            }
        }
    } catch (Exception e) {
        System.out.println("Problem with the DB file:");
        e.printStackTrace();
        return (-1);
    }
    return (0);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) BitSet(java.util.BitSet) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) CDKException(org.openscience.cdk.exception.CDKException) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) Screening(ambit2.smarts.Screening) RandomAccessFile(java.io.RandomAccessFile) FileReader(java.io.FileReader) Vector(java.util.Vector) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with EmptyMoleculeException

use of ambit2.base.exceptions.EmptyMoleculeException in project ambit-mirror by ideaconsult.

the class StructureKeysBitSetGenerator method prepareKeySequences.

protected synchronized void prepareKeySequences(List<String> keys, int nKeys) throws EmptyMoleculeException {
    smartsKeys = keys;
    IQueryAtomContainer query;
    sequences.clear();
    smartsQueries.clear();
    SmartsParser parser = new SmartsParser();
    for (int i = 0; i < nKeys; i++) {
        query = parser.parse(smartsKeys.get(i));
        // parser.setNeededDataFlags();       --> This should not be needed for the key smarts queries
        isoTester.setQuery(query);
        List<QuerySequenceElement> sequence = isoTester.transferSequenceToOwner();
        sequences.add(sequence);
        smartsQueries.add(query);
    }
}
Also used : SmartsParser(ambit2.smarts.SmartsParser) QuerySequenceElement(ambit2.smarts.QuerySequenceElement) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Aggregations

EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)8 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 IAtom (org.openscience.cdk.interfaces.IAtom)3 IRetroSynthRuleInstance (ambit2.reactions.rules.IRetroSynthRuleInstance)2 QuerySequenceElement (ambit2.smarts.QuerySequenceElement)2 GroupMatch (ambit2.smarts.groups.GroupMatch)2 StringWriter (java.io.StringWriter)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)2 Property (ambit2.base.data.Property)1 IsotopesProcessor (ambit2.core.processors.IsotopesProcessor)1 Substituent (ambit2.groupcontribution.nmr.Substituent)1 HAtomEnvironment (ambit2.groupcontribution.nmr.nmr_1h.HAtomEnvironment)1 HAtomEnvironmentInstance (ambit2.groupcontribution.nmr.nmr_1h.HAtomEnvironmentInstance)1 HNMRKnowledgeBase (ambit2.groupcontribution.nmr.nmr_1h.HNMRKnowledgeBase)1 GenericReaction (ambit2.reactions.GenericReaction)1 RetroSynthRuleInstance (ambit2.reactions.rules.RetroSynthRuleInstance)1 Screening (ambit2.smarts.Screening)1