Skip to content

Commit

Permalink
Fix rdkit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay committed Jul 22, 2024
1 parent 1bf58cc commit 10fc8df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
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
29 changes: 11 additions & 18 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 @@ -224,12 +223,6 @@ 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")

def test_default(self):
smi = "CN1C=NC2=C1C(=O)N(C(=O)N2C)C"
u = mda.Universe.from_smiles(smi, format='RDKIT')
Expand Down Expand Up @@ -288,17 +281,17 @@ def test_coordinates(self):
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)
[[-0.02209686, 0.00321505, 0.01651974],
[-0.6664637 , 0.8884155 , -0.10135844],
[-0.37778795, -0.8577519 , -0.58829606],
[ 0.09642092, -0.3151253 , 1.0637809 ],
[ 0.96992755, 0.2812466 , -0.39064613]],
[[-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_allclose(u.trajectory.coordinate_array, expected, rtol=1e-5)


class TestUniverse(object):
Expand Down

0 comments on commit 10fc8df

Please sign in to comment.