Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rdkit tests #4640

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions testsuite/MDAnalysisTests/converters/test_rdkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import MDAnalysis as mda
import numpy as np
from numpy.lib import NumpyVersion
import pytest
from MDAnalysis.topology.guessers import guess_atom_element
from MDAnalysisTests.datafiles import GRO, PDB_full, PDB_helix, mol2_molecule
Expand Down Expand Up @@ -56,8 +55,6 @@
reason="only for min dependencies build")
class TestRequiresRDKit(object):
def test_converter_requires_rdkit(self):
if NumpyVersion(np.__version__) >= "2.0.0":
pytest.skip("RDKit not compatible with NumPy 2")
u = mda.Universe(PDB_full)
with pytest.raises(ImportError,
match="RDKit is required for the RDKitConverter"):
Expand Down
10 changes: 3 additions & 7 deletions testsuite/MDAnalysisTests/converters/test_rdkit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import warnings
import pytest
import numpy as np
from numpy.lib import NumpyVersion
from numpy.testing import assert_equal

import MDAnalysis as mda
Expand All @@ -33,12 +32,9 @@

# TODO: remove these shims when RDKit
# has a release supporting NumPy 2
if NumpyVersion(np.__version__) < "2.0.0":
Chem = pytest.importorskip('rdkit.Chem')
AllChem = pytest.importorskip('rdkit.Chem.AllChem')
else:
Chem = pytest.importorskip("RDKit_does_not_support_NumPy_2")
AllChem = pytest.importorskip("RDKit_does_not_support_NumPy_2")
Chem = pytest.importorskip('rdkit.Chem')
AllChem = pytest.importorskip('rdkit.Chem.AllChem')


class RDKitParserBase(ParserBase):
parser = mda.converters.RDKitParser.RDKitParser
Expand Down
28 changes: 11 additions & 17 deletions testsuite/MDAnalysisTests/core/test_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import warnings

import numpy as np
from numpy.lib import NumpyVersion
from numpy.testing import (
assert_allclose,
assert_almost_equal,
Expand Down Expand Up @@ -225,10 +224,7 @@ def test_universe_empty_ROMol(self):

class TestUniverseFromSmiles(object):
def setup_class(self):
if NumpyVersion(np.__version__) < "2.0.0":
pytest.importorskip("rdkit.Chem")
else:
pytest.importorskip("RDKit_does_not_support_NumPy_2")
pytest.importorskip("rdkit.Chem")

def test_default(self):
smi = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
Expand Down Expand Up @@ -284,21 +280,19 @@ def test_rdkit_kwargs(self):


def test_coordinates(self):
# manually create the molecule to compare
RMeli marked this conversation as resolved.
Show resolved Hide resolved
from rdkit import Chem
from rdkit.Chem import AllChem
mol = Chem.MolFromSmiles('C', sanitize=True)
mol = Chem.AddHs(mol)
AllChem.EmbedMultipleConfs(mol, numConfs=2, randomSeed=42)
expected = [c.GetPositions() for c in mol.GetConformers()]

# now the mda way
u = mda.Universe.from_smiles("C", numConfs=2,
rdkit_kwargs=dict(randomSeed=42))
assert u.trajectory.n_frames == 2
expected = np.array([
[[-0.02209686, 0.00321505, 0.01651974],
[-0.6690088 , 0.8893599 , -0.1009085 ],
[-0.37778795, -0.8577519 , -0.58829606],
[ 0.09642092, -0.3151253 , 1.0637809 ],
[ 0.97247267, 0.28030226, -0.3910961 ]],
[[-0.0077073 , 0.00435363, 0.01834692],
[-0.61228824, -0.83705765, -0.38619974],
[-0.41925883, 0.9689095 , -0.3415968 ],
[ 0.03148226, -0.03256683, 1.1267245 ],
[ 1.0077721 , -0.10363862, -0.41727486]]], dtype=np.float32)
assert_almost_equal(u.trajectory.coordinate_array, expected)
assert_allclose(u.trajectory.coordinate_array, expected, rtol=1e-7)


class TestUniverse(object):
Expand Down
Loading