Esempio n. 1
0
 def test_readfile_unsupported(self):
     """
     Test importing of structure files with wrong format
     """
     self.assertIsNone(
         mol_read(self.ligand,
                  mol_format='non',
                  from_file=True,
                  toolkit=self.toolkit_name))
     self.assertIsNone(
         mol_read('/path/not/exist',
                  from_file=True,
                  toolkit=self.toolkit_name))
Esempio n. 2
0
    def test_readstring_noformat(self):
        """
        Test import benzene with unsupported format. Should raise ValueError
        """

        self.assertIsNone(
            mol_read("benzene", mol_format='noel', toolkit=self.toolkit_name))
Esempio n. 3
0
 def setUpClass(cls):
     """
     Import a few structures
     """
     for a, b in TEST_FILES.items():
         cls.test_structures[a] = mol_read(a,
                                           mol_format=b,
                                           toolkit=cls.toolkit_name)
Esempio n. 4
0
 def test_removeh(self):
     """
     Test removing hydrogens from structure
     """
     mol = mol_read(self.ligand,
                    mol_format='mol2',
                    toolkit=self.toolkit_name)
     mol = mol_removeh(mol)
     self.assertEqual(len(mol.atoms), 35)
Esempio n. 5
0
    def test_readstring_noconversion(self):
        """
        Test import iupac with unsuported notation.
        """

        self.assertIsNone(
            mol_read("Nosuchname",
                     mol_format='iupac',
                     toolkit=self.toolkit_name))
Esempio n. 6
0
    def test_make3D(self):
        """
        Test conversion 1D/2D to 3D structure representation
        """
        if self.toolkit_name == 'rdk' or self.toolkit_name == 'webel':
            self.skipTest("rdkit does not support mol2")

        x = mol_read('CCNCC', mol_format='smi', toolkit=self.toolkit_name)
        mol = mol_make3D(x)
        self.assertTrue(mol.dim == 3)
Esempio n. 7
0
    def test_conversion(self):
        """
        Test convert from acetylsaliclyic acid to INCHI and SMILES
        """

        for f, v in self.informats.items():

            mol = mol_read(v, mol_format=f, toolkit=self.toolkit_name)

            for a, b in self.outformats.items():
                output = mol_write(mol, mol_format=a)
                result = output.split()[0]
                self.assertEqual(result, b)
Esempio n. 8
0
    def test_readstring(self):
        """
        Test importing structure from string
        """
        if self.toolkit_name == 'rdk':
            self.skipTest("rdkit does not support sdf and mol2")

        for molformat, infile in self.formatexamples.items():
            if molformat in toolkits[self.toolkit_name].informats:
                if molformat in ('sdf', 'mol', 'mol2', 'cml'):
                    with open(infile, 'r') as lfile:
                        mol = mol_read(lfile.read(),
                                       mol_format=molformat,
                                       toolkit=self.toolkit_name)
                else:
                    mol = mol_read(infile,
                                   mol_format=molformat,
                                   toolkit=self.toolkit_name)

                # Opsin has no molwt property:
                if self.toolkit_name not in ['opsin', 'webel']:
                    self.assertAlmostEqual(mol.molwt, 180.1574, places=4)
Esempio n. 9
0
    def test_readfile(self):
        """
        Test importing structure file with correct format.
        """

        for molformat in ('sdf', 'mol', 'mol2', 'cml'):
            if molformat in toolkits[self.toolkit_name].informats:

                # Explicit import, format defined
                mol = mol_read(self.formatexamples[molformat],
                               mol_format=molformat,
                               from_file=True,
                               toolkit=self.toolkit_name)

                mol.addh()
                self.assertEqual(len(mol.atoms), 21)
Esempio n. 10
0
    def test_2d_draw(self):

        for toolkit in toolkits:

            # Does not support draw to file
            if toolkit == 'silverwebel':
                continue

            mol = mol_read('c1(cccnc1Nc1cc(ccc1)C(F)(F)F)C(=O)O',
                           mol_format='smi',
                           toolkit=toolkit)
            outfile = os.path.join(self.currpath,
                                   '../files/{0}_draw.png'.format(toolkit))
            if mol:
                mol.draw(filename=outfile, show=False)
                self.tmp_files.append(outfile)
                self.assertTrue(os.path.isfile(outfile))
Esempio n. 11
0
    def get_descriptors(request, claims):

        # Import the molecule
        mol = mol_validate_file_object(request['mol'])
        molobject = mol_read(mol['content'],
                             mol_format=mol['extension'],
                             toolkit=request["toolkit"])
        desc = molobject.calcdesc()

        if desc is not None:
            status = 'completed'
            output = desc
        else:
            status = 'failed'
            output = None

        return {'session': status, 'descriptors': output}
Esempio n. 12
0
    def test_addh(self):
        """
        Test addition of hydrogens
        """
        if self.toolkit_name == 'rdk':
            self.skipTest("rdkit does not support mol2")
        mol = mol_read(os.path.join(self.currpath, 'files/ccncc_3d_noh.mol2'),
                       from_file=True,
                       toolkit=self.toolkit_name)
        mol = mol_addh(mol)

        mol_reference = pybel.readfile(
            'mol2', os.path.join(self.currpath, 'files/ccncc_3d.mol2')).next()

        # compare properties
        p1 = mol.formula == mol_reference.formula
        p2 = (mol.exactmass - mol_reference.exactmass) < 1e-6

        self.assertTrue(all((p1, p2)))
Esempio n. 13
0
    def setUpClass(cls):
        """
        PlantsDockingTest class setup

        Read structure files for docking
        """

        smiles = [
            'c1(c(cccc1Nc1c(cccc1)C(=O)O)C)C', 'c12ccccc1nc1c(c2N)CCCC1',
            'c1ccc(c(c1)[N+](=O)[O-])[C@H]1C(=C(NC(=C1C(=O)OC)C)C)C(=O)OC',
            'c1cc(ccc1OCC)NC(=O)C', 'c12c3c(ccc1c(=O)cc(o2)c1ccccc1)cccc3',
            'c1cc(cc(c1N/C=N/O)C)CCCC', 'c1(cccnc1Nc1cc(ccc1)C(F)(F)F)C(=O)O',
            'c1ccc(c(c1C)OC[C@H](C)N)C', 'c1(OC[C@H](CNC(C)C)O)c2c(ccc1)cccc2',
            'c12ccccc1cccc2'
        ]

        mols = [
            mol_read(x, mol_format="smi", toolkit=cls.toolkit_name)
            for x in smiles
        ]
        cls.fps = [m.calcfp('maccs') for m in mols]
Esempio n. 14
0
    def calculate_chemical_similarity(self, request, claims):
        """
        Calculate the chemical similarity between two sets each containing one
        or more structures.
        The structure formats needs to be identical for all structures in both
        sets.

        see the file schemas/endpoints/chemical_similarity_request.v1.json file
        for a detail description of the input.
        """
        metric = request['metric']
        toolkit = request['toolkit']
        fp_format = request['fp_format']
        ci_cutoff = request['ci_cutoff']
        test_set = [
            mol_validate_file_object(obj) for obj in request['test_set']
        ]
        reference_set = [
            mol_validate_file_object(obj) for obj in request['reference_set']
        ]

        # Import the molecules
        test_mols = [
            mol_read(mol['content'],
                     mol_format=mol['extension'],
                     toolkit=toolkit) for mol in test_set
        ]
        reference_mols = [
            mol_read(mol['content'],
                     mol_format=mol['extension'],
                     toolkit=toolkit) for mol in reference_set
        ]

        # Calculate the fingerprints
        test_fps = [m.calcfp(fp_format) for m in test_mols]
        reference_fps = [m.calcfp(fp_format) for m in reference_mols]

        # Calculate the similarity matrix
        simmat = mol_fingerprint_cross_similarity(test_fps,
                                                  reference_fps,
                                                  toolkit,
                                                  metric=metric)

        # Calculate average similarity, maximum similarity and report the index
        # of the reference case with maximum similarity.
        stats = [
            numpy.mean(simmat, axis=1),
            numpy.max(simmat, axis=1),
            numpy.argmax(simmat, axis=1)
        ]

        # Format as Pandas DataFrame and export as JSON
        stats = pandas.DataFrame(stats).T
        stats.columns = ['average', 'max_sim', 'idx_max_sim']
        stats['idx_max_sim'] = stats['idx_max_sim'].astype(int)

        # Calculate applicability domain CI value if ci_cutoff defined
        if ci_cutoff:
            stats['CI'] = (stats['average'] >= ci_cutoff).astype(int)
            self.log.info(
                'Chemical similarity AD analysis with cutoff {0}'.format(
                    ci_cutoff))

        # Create workdir and save file
        workdir = request['workdir']
        if not os.path.isdir(workdir):
            os.mkdir(workdir)
            self.log.debug('Create working directory: {0}'.format(workdir))
        filepath = os.path.join(workdir, 'adan_chemical_similarity.csv')
        stats.to_csv(filepath)

        status = 'completed'
        return {'status': status, 'results': stats.to_dict()}