Exemple #1
0
def test_align_ligands_autodock4():
    from rdkit.rdBase import DisableLog
    DisableLog('rdApp.*')

    ligands_dict = {
        'FXR_10': 'test_data/align_ligands_autodock4/FXR_10.dlg',
        'FXR_12': 'test_data/align_ligands_autodock4/FXR_12.dlg'
    }

    align_data = align_ligands(
        pybel.readfile(
            'pdb',
            'test_data/align_ligands_autodock4/1dvwb_altered.pdb').__next__(),
        ligands_dict,
        poses_reference_structure=
        'test_data/align_ligands_autodock4/FXR_receptor.pdbqt',
        pose_loader='autodock4',
        cluster_docking_data={'FXR_12': 2},
        verbosity=-1)

    with open('test_data/align_ligands_autodock4/results_autodock4.pkl',
              'rb') as fh:
        reference_position = pickle.load(fh)

    for each_name, each_mol in align_data.items():
        assert (extract_coordinates(each_mol) -
                reference_position[each_name]).sum() < dist_tolerance
Exemple #2
0
def test_align_ligands_superimpose1():
    from rdkit.rdBase import DisableLog
    DisableLog('rdApp.*')

    from mol_util import adjust_query_properties
    from rdkit.Chem.rdMolAlign import GetBestRMS

    ligands_dict = {
        'FXR_10': 'test_data/align_ligands_superimpose/FXR_10.mol2',
        'FXR_12': 'test_data/align_ligands_superimpose/FXR_12.mol2'
    }
    result_file = 'test_data/align_ligands_superimpose/FXR_10_result.pdb'

    align_data = align_ligands(
        pybel.readfile(
            'pdb', 'test_data/align_ligands_pdb/1dvwb_altered.pdb').__next__(),
        ligands_dict,
        reference_pose_superimpose=
        'test_data/align_ligands_superimpose/FXR_10_ref.mol2',
        poses_reference_structure='test_data/align_ligands_pdb/1dvwb.pdb',
        pose_loader='superimpose',
        verbosity=-1)

    resultmol = adjust_query_properties(rdkit.Chem.MolFromPDBFile(result_file))
    assert (GetBestRMS(resultmol, align_data['FXR_10'])) < 0.1
    fxr12rms = GetBestRMS(resultmol,
                          align_data['FXR_12'],
                          map=[[(30, 0), (11, 1), (23, 2), (20, 3), (26, 35),
                                (32, 34), (28, 6), (12, 7), (1, 8), (2, 9),
                                (16, 10), (3, 11), (8, 12), (18, 13), (7, 14),
                                (19, 15), (9, 16), (0, 17), (14, 18), (13, 19),
                                (4, 27), (17, 28), (27, 29),
                                (33, 30), (29, 31), (15, 32), (5, 33), (31, 5),
                                (25, 4)]])
    assert fxr12rms < 1
Exemple #3
0
 def setUp(self):
     self.dataset = dict()
     self.dataset_inchi = dict()
     inf = gzip.open(os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
                                  'pubchem-hard-set.sdf.gz'),'r')
     self.dataset['problematic'] = ForwardSDMolSupplier(inf,sanitize=False,removeHs=False)
     with open(os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
                            'pubchem-hard-set.inchi'),'rb') as inF:
         self.dataset_inchi['problematic'] = load(inF)
     # disable logging
     DisableLog('rdApp.warning')
Exemple #4
0
 def setUp(self):
     self.dataset = dict()
     self.dataset_inchi = dict()
     self.dataset['problematic'] = GzippedSDMolSupplier(
             os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
                 'pubchem-hard-set.sdf.gz'))
     _ = file(os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
         'pubchem-hard-set.inchi'))
     self.dataset_inchi['problematic'] = load(_)
     _.close()
     # disable logging
     DisableLog('rdApp.warning')
Exemple #5
0
 def setUp(self):
     self.dataset = dict()
     self.dataset_inchi = dict()
     inf = gzip.open(
         os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
                      'pubchem-hard-set.sdf.gz'), 'r')
     self.dataset['problematic'] = ForwardSDMolSupplier(inf,
                                                        sanitize=False,
                                                        removeHs=False)
     with open(
             os.path.join(RDConfig.RDCodeDir, 'Chem/test_data',
                          'pubchem-hard-set.inchi'), 'r') as intF:
         buf = intF.read().replace('\r\n', '\n').encode('latin1')
         intF.close()
     with io.BytesIO(buf) as inF:
         pkl = inF.read()
     self.dataset_inchi['problematic'] = loads(pkl, encoding='latin1')
     # disable logging
     DisableLog('rdApp.warning')
Exemple #6
0
 def setLevel(self, val):
     global _levels
     for i in range(val, len(_levels)):
         EnableLog(_levels[i])
     for i in range(0, val):
         DisableLog(_levels[i])
Exemple #7
0
def read_options(argument_parser,
                 unpack_section='',
                 user_config_file=None,
                 default_internal_file=None,
                 verbosity=0):
    """ Process configuration files and command line arguments. Resolution order is arguments > user_config_file >
        default_config_file.

    :param argparse.ArgumentParser argument_parser: command line arguments to be processed
    :param str unpack_section: unpack all variables from this section from user_config_file (if present) and
                               default_config_file
    :param str user_config_file: read this configuration file, takes precedence over default_config_file
    :param str default_internal_file: read internal paths and vars from this file, this will not be superseeded by user
                                      input
    :param verbosity: set the verbosity level
    :rtype: all_classes.Namedlist
    """

    os_util.local_print(
        'Entering read_options(argument_parser={}, unpack_section={}, user_config_file={}, '
        'default_config_file={}, verbosity={})'
        ''.format(argument_parser, unpack_section, user_config_file,
                  default_internal_file, verbosity),
        msg_verbosity=os_util.verbosity_level.debug,
        current_verbosity=verbosity)

    internals = configparser.ConfigParser()
    if not default_internal_file:
        read_data = internals.read(
            os.path.join(os.path.dirname(__file__), 'config', 'internal.ini'))
    else:
        read_data = internals.read(default_internal_file)

    if not read_data:
        os_util.local_print(
            'Failed to read internal data file. Cannot continue. Check your install, this should not '
            'happen'.format(default_internal_file if default_internal_file else
                            'config/internal.ini'),
            current_verbosity=verbosity,
            msg_verbosity=os_util.verbosity_level.error)
        raise SystemExit(-1)

    # Reads command line parameters
    arguments = argument_parser.parse_args()

    # Reads defaults from default_config_file or from default location
    default_config_file = os.path.join(os.path.dirname(__file__),
                                       internals['default']['default_config'])

    if arguments.config_file is not None and user_config_file is None:
        user_config_file = arguments.config_file

    result_data = configparser.ConfigParser()

    try:
        read_files = result_data.read(default_config_file)
    except IOError:
        os_util.local_print(
            'Failed to read the configuration file {}. I cannot continue without it.'
            ''.format(default_config_file),
            msg_verbosity=os_util.verbosity_level.error,
            current_verbosity=verbosity)
        raise SystemExit(1)
    else:
        if not read_files:
            os_util.local_print(
                'Failed to read the configuration file {}. I cannot continue without it.'
                ''.format(default_config_file),
                msg_verbosity=os_util.verbosity_level.error,
                current_verbosity=verbosity)
            raise SystemExit(1)

    result_data = {
        key: dict(result_data.items(key))
        for key in result_data.sections()
    }
    if user_config_file:
        user_file = configparser.ConfigParser()

        if not user_file.read(user_config_file):
            os_util.local_print(
                'Failed to read the configuration file {}. I cannot continue without it.'
                ''.format(user_config_file),
                msg_verbosity=os_util.verbosity_level.error,
                current_verbosity=verbosity)
            raise SystemExit(1)

        result_data = os_util.recursive_update(
            result_data,
            {key: dict(user_file.items(key))
             for key in user_file.sections()})

    if unpack_section:
        # Copy all info in section unpack_section to top level
        result_data = os_util.recursive_update(
            dict(result_data['globals']), dict(result_data[unpack_section]))

    # Overwrites values in result_data (ie: read from config files) with those from command line
    result_data.update(
        dict(filter(lambda x: x[1] is not None,
                    vars(arguments).items())))

    # If values were not provided in config files, load them from argparse defaults (None for most cases)
    result_data.update(
        {k: v
         for k, v in vars(arguments).items() if k not in result_data})

    # Detect all types in result_data
    result_data = all_classes.Namespace(
        os_util.recursive_map(os_util.detect_type, dict(result_data)))

    # Programmatically set some global variables
    if result_data.verbose is None:
        result_data.verbose = 0

    if result_data.quiet:
        if result_data.verbose > 0:
            os_util.local_print(
                'I cannot be quiet and verbose at once. Please, select only one of them.',
                msg_verbosity=os_util.verbosity_level.error,
                current_verbosity=verbosity)
            raise SystemExit(1)
        else:
            result_data.verbose = -1

    if result_data.verbose <= 2:
        from rdkit.rdBase import DisableLog
        DisableLog('rdApp.error')

    if result_data.threads == 0 or result_data.threads is None:
        try:
            from os import sched_getaffinity
        except ImportError:
            from os import cpu_count
            result_data.threads = cpu_count()
        else:
            result_data.threads = len(sched_getaffinity(0))
    if type(result_data.threads
            ) != int or result_data.threads < -1 or result_data.threads == 0:
        os_util.local_print(
            'Invalid number of threads supplied or detected. Falling back to threads = 1',
            msg_verbosity=os_util.verbosity_level.warning,
            current_verbosity=verbosity)
        result_data.threads = 1

    if result_data.no_checks is None:
        result_data.no_checks = False

    if result_data.progress_file is None:
        result_data.progress_file = 'progress.pkl'

    result_data['internal'] = all_classes.Namespace(
        {key: dict(internals.items(key))
         for key in internals.sections()})

    return result_data