<commit_before>import os
from tempfile import mkdtemp, NamedTemporaryFile

import pytest
from numpy.testing import assert_array_equal, assert_array_almost_equal

import pandas as pd

import oddt
from oddt.utils import method_caller
from oddt.spatial import rmsd
from oddt.scoring import scorer
from oddt.scoring.functions import rfscore, nnscore
from oddt.virtualscreening import virtualscreening

test_data_dir = os.path.dirname(os.path.abspath(__file__))

# common file names
dude_data_dir = os.path.join(test_data_dir, 'data', 'dude', 'xiap')
xiap_crystal_ligand = os.path.join(dude_data_dir, 'crystal_ligand.sdf')
xiap_protein = os.path.join(dude_data_dir, 'receptor_rdkit.pdb')
xiap_actives_docked = os.path.join(dude_data_dir, 'actives_docked.sdf')


def test_vs_scoring_vina():
    """VS scoring (Vina) tests"""
    vs = virtualscreening(n_cpu=1)
    vs.load_ligands('sdf', xiap_crystal_ligand)
    vs.score(function='autodock_vina', protein=xiap_protein)
    mols = list(vs.fetch())
    assert len(mols) == 1
    mol_data = mols[0].data
    assert 'vina_affinity' in mol_data
    assert 'vina_gauss1' in mol_data
    assert 'vina_gauss2' in mol_data
    assert 'vina_hydrogen' in mol_data
    assert 'vina_hydrophobic' in mol_data
    assert 'vina_repulsion' in mol_data
    assert mol_data['vina_affinity'] == '-3.57594'
    assert mol_data['vina_gauss1'] == '63.01213'
    assert mol_data['vina_gauss2'] == '999.07625'
    assert mol_data['vina_hydrogen'] == '0.0'
    assert mol_data['vina_hydrophobic'] == '26.12648'
    assert mol_data['vina_repulsion'] == '3.63178'


def test_vs_docking():
    """VS docking (Vina) tests"""
    vs = virtualscreening(n_cpu=1)
    vs.load_ligands('sdf', xiap_crystal_ligand)

    # bad docking engine
    with pytest.raises(ValueError):
        vs.dock('srina', 'prot.pdb')

    vs.dock(engine='autodock_vina',
            protein=xiap_protein,
            auto_ligand=xiap_crystal_ligand,
            exhaustiveness=1,
            energy_range=6,
            num_modes=7,
            size=(20, 20, 20),
            seed=0)
    mols = list(vs.fetch())
    assert len(mols) == 7
    mol_data = mols[0].data
    assert 'vina_affinity' in mol_data
    assert 'vina_rmsd_lb' in mol_data
    assert 'vina_rmsd_ub' in mol_data
    if oddt.toolkit.backend == 'ob' and oddt.toolkit.__version__ < '2.4.0':
        vina_scores = [-5.3, -4.0, -3.8, -3.7, -3.4, -3.4, -3.0]
    else:
        vina_scores = [-6.3, -6.0, -5.8, -5.8, -3.9, -3.0, -1.1]
    assert_array_equal([float(m.data['vina_affinity']) for m in mols], vina_scores)

    # verify the SMILES of molecules
    ref_mol = next(oddt.toolkit.readfile('sdf', xiap_crystal_ligand))

    if oddt.toolkit.backend == 'ob' and oddt.toolkit.__version__ < '2.4.0':
        # OB 2.3.2 will fail the following, since Hs are removed, etc.
        pass
    else:
        vina_rmsd = [8.153314, 5.32554, 8.514586, 8.510169, 9.060128, 8.995098,
                     8.626776]
        assert_array_equal([mol.smiles for mol in mols],
                           [ref_mol.smiles] * len(mols))

        assert_array_almost_equal([rmsd(ref_mol, mol, method='min_symmetry')
                                   for mol in mols], vina_rmsd)

<commit_msg>One result for OB<commit_after>import os
from tempfile import mkdtemp, NamedTemporaryFile

import pytest
from numpy.testing import assert_array_equal, assert_array_almost_equal

import pandas as pd

import oddt
from oddt.utils import method_caller
from oddt.spatial import rmsd
from oddt.scoring import scorer
from oddt.scoring.functions import rfscore, nnscore
from oddt.virtualscreening import virtualscreening

test_data_dir = os.path.dirname(os.path.abspath(__file__))

# common file names
dude_data_dir = os.path.join(test_data_dir, 'data', 'dude', 'xiap')
xiap_crystal_ligand = os.path.join(dude_data_dir, 'crystal_ligand.sdf')
xiap_protein = os.path.join(dude_data_dir, 'receptor_rdkit.pdb')
xiap_actives_docked = os.path.join(dude_data_dir, 'actives_docked.sdf')


def test_vs_scoring_vina():
    """VS scoring (Vina) tests"""
    vs = virtualscreening(n_cpu=1)
    vs.load_ligands('sdf', xiap_crystal_ligand)
    vs.score(function='autodock_vina', protein=xiap_protein)
    mols = list(vs.fetch())
    assert len(mols) == 1
    mol_data = mols[0].data
    assert 'vina_affinity' in mol_data
    assert 'vina_gauss1' in mol_data
    assert 'vina_gauss2' in mol_data
    assert 'vina_hydrogen' in mol_data
    assert 'vina_hydrophobic' in mol_data
    assert 'vina_repulsion' in mol_data
    assert mol_data['vina_affinity'] == '-3.57594'
    assert mol_data['vina_gauss1'] == '63.01213'
    assert mol_data['vina_gauss2'] == '999.07625'
    assert mol_data['vina_hydrogen'] == '0.0'
    assert mol_data['vina_hydrophobic'] == '26.12648'
    assert mol_data['vina_repulsion'] == '3.63178'


def test_vs_docking():
    """VS docking (Vina) tests"""
    vs = virtualscreening(n_cpu=1)
    vs.load_ligands('sdf', xiap_crystal_ligand)

    # bad docking engine
    with pytest.raises(ValueError):
        vs.dock('srina', 'prot.pdb')

    vs.dock(engine='autodock_vina',
            protein=xiap_protein,
            auto_ligand=xiap_crystal_ligand,
            exhaustiveness=1,
            energy_range=6,
            num_modes=7,
            size=(20, 20, 20),
            seed=0)
    mols = list(vs.fetch())
    assert len(mols) == 7
    mol_data = mols[0].data
    assert 'vina_affinity' in mol_data
    assert 'vina_rmsd_lb' in mol_data
    assert 'vina_rmsd_ub' in mol_data
    if oddt.toolkit.backend == 'ob':
        vina_scores = [-5.3, -4.0, -3.8, -3.7, -3.4, -3.4, -3.0]
    else:
        vina_scores = [-6.3, -6.0, -5.8, -5.8, -3.9, -3.0, -1.1]
    assert_array_equal([float(m.data['vina_affinity']) for m in mols], vina_scores)

    # verify the SMILES of molecules
    ref_mol = next(oddt.toolkit.readfile('sdf', xiap_crystal_ligand))

    if oddt.toolkit.backend == 'ob' and oddt.toolkit.__version__ < '2.4.0':
        # OB 2.3.2 will fail the following, since Hs are removed, etc.
        pass
    else:
        vina_rmsd = [8.153314, 5.32554, 8.514586, 8.510169, 9.060128, 8.995098,
                     8.626776]
        assert_array_equal([mol.smiles for mol in mols],
                           [ref_mol.smiles] * len(mols))

        assert_array_almost_equal([rmsd(ref_mol, mol, method='min_symmetry')
                                   for mol in mols], vina_rmsd)


{'fraction_non_alphanumeric': 0.12291634210936282, 'fraction_numerical': 0.04346471412992678, 'mean_word_length': 3.1742522756827047, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5084889', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2441, 'n_words': 492}