Search in sources :

Example 11 with AtomContainerSet

use of org.openscience.cdk.AtomContainerSet in project cdk by cdk.

the class MoSSOutputReaderTest method testExampleFile_SupportColumns.

@Test
public void testExampleFile_SupportColumns() throws Exception {
    String filename = "TKO.mossoutput";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MoSSOutputReader reader = new MoSSOutputReader(ins);
    IAtomContainerSet moleculeSet = new AtomContainerSet();
    moleculeSet = reader.read(moleculeSet);
    Assert.assertEquals(5.06, Double.valueOf(moleculeSet.getAtomContainer(0).getProperty("focusSupport").toString()), 0.01);
    Assert.assertEquals(1.74, Double.valueOf(moleculeSet.getAtomContainer(0).getProperty("complementSupport").toString()), 0.01);
}
Also used : InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AtomContainerSet(org.openscience.cdk.AtomContainerSet) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 12 with AtomContainerSet

use of org.openscience.cdk.AtomContainerSet in project cdk by cdk.

the class SMILESReaderTest method testReadingSmiFile_1.

@Test
public void testReadingSmiFile_1() throws Exception {
    String filename = "smiles.smi";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    SMILESReader reader = new SMILESReader(ins);
    IAtomContainerSet som = reader.read(new AtomContainerSet());
    String name;
    IAtomContainer thisMol = som.getAtomContainer(0);
    name = ((String) thisMol.getProperty("SMIdbNAME")).toString();
    Assert.assertEquals("benzene", name);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IteratingSMILESReader(org.openscience.cdk.io.iterator.IteratingSMILESReader) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 13 with AtomContainerSet

use of org.openscience.cdk.AtomContainerSet in project ambit-mirror by ideaconsult.

the class SMIRKSManager method applyTransformationWithSingleCopyForEachPos.

public IAtomContainerSet applyTransformationWithSingleCopyForEachPos(IAtomContainer target, IAcceptable selection, SMIRKSReaction reaction, SSM_MODE SSMode) throws Exception {
    SmartsParser.prepareTargetForSMARTSSearch(reaction.reactantFlags, target);
    if (reaction.reactantFlags.hasRecursiveSmarts)
        mapRecursiveAtomsAgainstTarget(reaction.reactantRecursiveAtoms, target);
    isoTester.setQuery(reaction.reactant);
    List<List<IAtom>> rMaps0;
    switch(SSMode) {
        case SSM_NON_OVERLAPPING:
            rMaps0 = getNonOverlappingMappings(target);
            break;
        case SSM_NON_IDENTICAL:
            rMaps0 = getNonIdenticalMappings(target);
            break;
        case SSM_ALL:
            rMaps0 = getAllMappings(target);
            break;
        default:
            rMaps0 = getNonIdenticalMappings(target);
    }
    if (rMaps0.size() == 0)
        return null;
    List<List<IAtom>> rMaps;
    // Preliminary filtration by means of IAcceptable
    if (selection == null)
        rMaps = rMaps0;
    else {
        rMaps = new ArrayList<List<IAtom>>();
        for (int i = 0; i < rMaps0.size(); i++) {
            if (selection.accept(rMaps0.get(i)))
                rMaps.add(rMaps0.get(i));
        }
    }
    if (rMaps.size() == 0)
        return null;
    if (FlagFilterEquivalentMappings) {
        eqTester.setTarget(target);
        eqTester.quickFindEquivalentTerminalHAtoms();
        rMaps = eqTester.filterEquivalentMappings(rMaps);
    }
    IAtomContainerSet resSet = new AtomContainerSet();
    for (int i = 0; i < rMaps.size(); i++) {
        List<List<IAtom>> vMaps = new ArrayList<List<IAtom>>();
        vMaps.add(rMaps.get(i));
        IAtomContainer product = applyTransformationsAtLocationsWithCloning(target, vMaps, reaction);
        if (FlagProcessResultStructures)
            processProduct(product);
        if (FlagCheckResultStereo)
            StereoChemUtils.checkStereoElements(product);
        resSet.addAtomContainer(product);
    }
    return resSet;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 14 with AtomContainerSet

use of org.openscience.cdk.AtomContainerSet in project ambit-mirror by ideaconsult.

the class SMIRKSManager method applyTransformationWithCombinedOverlappedPos.

/*
     * This transformation is applied in SSM_NON_IDENTICAL mode where the
     * overlapping mappings at particular site produce multiple copies of the
     * molecule.
     */
public IAtomContainerSet applyTransformationWithCombinedOverlappedPos(IAtomContainer target, IAcceptable selection, SMIRKSReaction reaction) throws Exception {
    SmartsParser.prepareTargetForSMARTSSearch(reaction.reactantFlags, target);
    if (reaction.reactantFlags.hasRecursiveSmarts)
        mapRecursiveAtomsAgainstTarget(reaction.reactantRecursiveAtoms, target);
    isoTester.setQuery(reaction.reactant);
    List<List<IAtom>> rMaps0 = getNonIdenticalMappings(target);
    if (rMaps0.size() == 0)
        return null;
    List<List<IAtom>> rMaps;
    // Preliminary filtration by means of IAcceptable
    if (selection == null)
        rMaps = rMaps0;
    else {
        rMaps = new ArrayList<List<IAtom>>();
        for (int i = 0; i < rMaps0.size(); i++) {
            if (selection.accept(rMaps0.get(i)))
                rMaps.add(rMaps0.get(i));
        }
    }
    if (rMaps.size() == 0)
        return null;
    if (FlagFilterEquivalentMappings) {
        eqTester.setTarget(target);
        eqTester.quickFindEquivalentTerminalHAtoms();
        rMaps = eqTester.filterEquivalentMappings(rMaps);
    // System.out.println("FilteredMappings");
    // for (int i = 0; i < rMaps2.size(); i++)
    // printSSMap(target, rMaps2.get(i));
    }
    IAtomContainerSet resSet = new AtomContainerSet();
    if (rMaps.size() == 1) {
        IAtomContainer product = applyTransformationsAtLocationsWithCloning(target, rMaps, reaction);
        if (FlagProcessResultStructures)
            processProduct(product);
        if (FlagCheckResultStereo)
            StereoChemUtils.checkStereoElements(product);
        resSet.addAtomContainer(product);
        return (resSet);
    }
    // Make mapping clusters/groups
    List<List<Integer>> clusterIndexes = isoTester.getOverlappedMappingClusters(rMaps);
    // printMappingClusters(clusterIndexes, target);
    // Generate all combinations:
    // Each combination is represented as a number where each digit is
    // represents the choice from each cluster
    int[] comb = new int[clusterIndexes.size()];
    for (int i = 0; i < comb.length; i++) comb[i] = 0;
    int digit = 0;
    do {
        // Prepare current combination
        List<List<IAtom>> combMaps = new ArrayList<List<IAtom>>();
        for (int i = 0; i < comb.length; i++) {
            int index = clusterIndexes.get(i).get(comb[i]).intValue();
            combMaps.add(rMaps.get(index));
        }
        // Apply the transformation for the particular combination of
        // locations with cloning
        IAtomContainer product = applyTransformationsAtLocationsWithCloning(target, combMaps, reaction);
        if (FlagProcessResultStructures)
            processProduct(product);
        if (FlagCheckResultStereo)
            StereoChemUtils.checkStereoElements(product);
        resSet.addAtomContainer(product);
        // Generation of next combination
        digit = 0;
        while (digit < comb.length) {
            comb[digit]++;
            if (comb[digit] == clusterIndexes.get(digit).size()) {
                comb[digit] = 0;
                digit++;
            } else
                break;
        }
    } while (digit < comb.length);
    return resSet;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 15 with AtomContainerSet

use of org.openscience.cdk.AtomContainerSet in project MORTAR by FelixBaensch.

the class Importer method importSDFile.

// 
/**
 * Imports an SD file.
 *
 * @param aFile sdf
 * @return the imported molecules in an IAtomContainerSet
 * @throws FileNotFoundException if a file input stream cannot be opened for the given file
 */
private IAtomContainerSet importSDFile(File aFile) throws FileNotFoundException {
    IAtomContainerSet tmpAtomContainerSet = new AtomContainerSet();
    IteratingSDFReader tmpSDFReader = new IteratingSDFReader(new FileInputStream(aFile), DefaultChemObjectBuilder.getInstance());
    int tmpCounter = 0;
    while (!Thread.currentThread().isInterrupted() && tmpSDFReader.hasNext()) {
        IAtomContainer tmpAtomContainer = tmpSDFReader.next();
        String tmpName = this.findMoleculeName(tmpAtomContainer);
        if (tmpName == null || tmpName.isBlank() || tmpName.isEmpty())
            tmpName = FileUtil.getFileNameWithoutExtension(aFile) + tmpCounter;
        tmpAtomContainer.setProperty(Importer.MOLECULE_NAME_PROPERTY_KEY, tmpName);
        tmpAtomContainerSet.addAtomContainer(tmpAtomContainer);
        tmpCounter++;
    }
    return tmpAtomContainerSet;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) AtomContainerSet(org.openscience.cdk.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) FileInputStream(java.io.FileInputStream)

Aggregations

AtomContainerSet (org.openscience.cdk.AtomContainerSet)30 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)30 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)26 Test (org.junit.Test)18 AtomContainer (org.openscience.cdk.AtomContainer)16 IAtom (org.openscience.cdk.interfaces.IAtom)12 Atom (org.openscience.cdk.Atom)11 InputStream (java.io.InputStream)6 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)6 StringWriter (java.io.StringWriter)5 ChemObjectWriterTest (org.openscience.cdk.test.io.ChemObjectWriterTest)5 BufferedReader (java.io.BufferedReader)4 FileReader (java.io.FileReader)4 ArrayList (java.util.ArrayList)4 ChemModel (org.openscience.cdk.ChemModel)4 CDKException (org.openscience.cdk.exception.CDKException)4 SDFWriter (org.openscience.cdk.io.SDFWriter)4 IteratingSMILESReader (org.openscience.cdk.io.iterator.IteratingSMILESReader)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3