diff --git a/.github/workflows/PR_test.yml b/.github/workflows/PR_test.yml index 97670759..c08fa268 100755 --- a/.github/workflows/PR_test.yml +++ b/.github/workflows/PR_test.yml @@ -14,10 +14,10 @@ jobs: python-version: [ 3.11 ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v7 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v7 with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/commit_test.yml b/.github/workflows/commit_test.yml index e63eced9..27c0048e 100644 --- a/.github/workflows/commit_test.yml +++ b/.github/workflows/commit_test.yml @@ -19,13 +19,13 @@ jobs: python-version: [3.11] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v7 with: ref: ${{ inputs.myCommit }} - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v7 with: python-version: ${{ matrix.python-version }} diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 43d36b05..a0213c4b 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -10,12 +10,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 - - name: Set up Python 3.9 - uses: actions/setup-python@v1 + uses: actions/checkout@v7 + - name: Set up Python 3.12 + uses: actions/setup-python@v7 with: - python-version: 3.9 - - uses: actions/cache@v2 + python-version: "3.12" + - uses: actions/cache@v6 with: path: | ~/.cache/pip @@ -42,7 +42,7 @@ jobs: sphinx-build -E -b html ./docs/source ./pages - name: Deploy to GH-Pages if: always() - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./pages diff --git a/.gitignore b/.gitignore index 74b5a9f5..e05f192c 100755 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ examples/**/*_rotlib.npz docs/build docs/make.bat docs/Makefile + +# MDAnalysis trajectory offset caches +*_offsets.npz +*_offsets.lock diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100755 index ec24a32b..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,52 +0,0 @@ -workflow: - rules: - - if: $CI_COMMIT_BRANCH == 'main' - -.test_template: &test_definition - script: - - python -V # Print out python version for debugging - - python -m pip install -U pip - - pip install . - - cd tests - - pytest - rules: - - changes: - - tests/* - - chiLife/data/* - - chiLife/*.py - -test:3.8: - image: python:3.8 - <<: *test_definition - -test:3.9: - image: python:3.9 - <<: *test_definition - -test:3.10: - image: python:3.10 - <<: *test_definition - - # test:3.11: - # image: python:3.11 - # <<: *test_definition - - -.build_template: &build_definition - script: - - python setup.py bdist_wheel - # an alternative approach is to install and run: - - pip install dist/* - # run the command here - artifacts: - paths: - - dist/*.whl - - #run:3.8: - # image: python:3.8 - # <<: *build_definition - - #run:3.9: - # image: python:3.8 - # <<: *build_definition - # diff --git a/pyproject.toml b/pyproject.toml old mode 100755 new mode 100644 index d63f5b75..9ec063f0 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,47 +1,66 @@ [project] name = "chilife" -description = 'A package for modeling non-canonical amino acid side chain ensembles.' -readme = 'README.md' -license= {name = 'GNU GPLv3', file = 'LICENSE'} -authors=[{name = 'Maxx Tessmer', email='mhtessmer@gmail.com'}, - {name = 'Stefan Stoll', email='stst@uw.edu'}] -keywords=['Spin-label', 'EPR', 'DEER', 'PELDOR', 'Side-chain'] +description = "A package for modeling non-canonical amino acid side chain ensembles." +readme = "README.md" +license = "GPL-3.0-only" +license-files = ["LICENSE"] +authors = [ + {name = "Maxx Tessmer", email = "mhtessmer@gmail.com"}, + {name = "Stefan Stoll", email = "stst@uw.edu"}, +] +keywords = ["Spin-label", "EPR", "DEER", "PELDOR", "Side-chain"] dynamic = ["version"] -requires-python = ">= 3.8,<3.14" -dependencies = ['numpy>=1.23.0', - 'scipy>=1.6.3', - 'matplotlib>=3.3.4', - 'numba>=0.55.0', - 'mdanalysis>=2.0.0', - 'tqdm>=4.45.0', - 'pytest>=6.2.2', - 'memoization>=0.3.1', - 'igraph>=0.10.3', - 'rtoml>=0.9.0'] - -classifiers=['License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12'] +requires-python = ">=3.10" +dependencies = [ + "numpy>=1.23.0", + "scipy>=1.8.0", + "matplotlib>=3.5.0", + "numba>=0.56.2", + "mdanalysis>=2.2.0", + "tqdm>=4.45.0", + "pytest>=6.2.2", + "memoization>=0.3.1", + "igraph>=0.10.3", + "rtoml>=0.9.0", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Chemistry", + "Topic :: Scientific/Engineering :: Physics", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] [project.urls] -homepage = 'https://github.com/StollLab/chiLife' +homepage = "https://github.com/StollLab/chiLife" documentation = "https://stolllab.github.io/chiLife/" [project.optional-dependencies] smiles2residue = ["rdkit>=2023.9.6"] +openmm = ["openmm>=8.1.1"] [tool.setuptools] -script-files = ['scripts/update_rotlib.py', 'scripts/oldProteinIC.py'] +script-files = ["scripts/update_rotlib.py", "scripts/oldProteinIC.py"] [tool.setuptools.package-data] -chilife = ['data/*', 'data/*/*', 'data/*/*/*'] +chilife = ["data/**/*"] [tool.setuptools.dynamic] version = {attr = "chilife.__version__"} +[tool.pytest.ini_options] +addopts = ["-ra", "--strict-markers"] +filterwarnings = [ + # Tests build single-frame in-memory MDAnalysis Universes directly; chiLife's own loaders already suppress this. + "ignore:Reader has no dt information:UserWarning", +] + [build-system] -requires = ["setuptools", "matplotlib", "wheel"] +requires = ["setuptools>=77", "matplotlib"] build-backend = "setuptools.build_meta" diff --git a/src/chilife/IntrinsicLabel.py b/src/chilife/IntrinsicLabel.py index 43d24fbb..34f4ca23 100644 --- a/src/chilife/IntrinsicLabel.py +++ b/src/chilife/IntrinsicLabel.py @@ -58,7 +58,7 @@ def __init__(self, res, atom_selection, spin_atoms=None, name='IntrinsicLabel'): sa_mask = np.isin(self.atom_names, self.spin_atoms,) self.spin_idx = np.argwhere(sa_mask) - self.spin_idx.shape = -1 + self.spin_idx = self.spin_idx.reshape(-1) self.atoms = [FreeAtom(atom.name, atom.type, idx, atom.resname, atom.resnum, atom.position) for idx, atom in enumerate(self._selection.atoms)] diff --git a/src/chilife/MolSys.py b/src/chilife/MolSys.py index 763786db..7ff0dc12 100644 --- a/src/chilife/MolSys.py +++ b/src/chilife/MolSys.py @@ -33,6 +33,7 @@ "chains", "occupancies", "bs", + "tempfactors", "segs", "segids", "atypes", @@ -70,6 +71,7 @@ "segid": "segids", "charge": "charges", "bfactor": "bs", + "tempfactor": "bs", "qfactor": "occupancies", "occupancy": "occupancies", "segix": "segixs", @@ -1168,7 +1170,7 @@ def from_cif(cls, file_name): icodes = np.array(atom_site_data["pdbx_PDB_ins_code"][:n_atoms]) icodes[icodes == "?"] = "" - segs = np.char.array(atom_site_data["label_asym_id"][:n_atoms]) + segs = np.array(atom_site_data["label_asym_id"][:n_atoms], dtype=str) raw_eid = atom_site_data["label_entity_id"][:n_atoms] parsed_eid = np.array( @@ -1693,6 +1695,12 @@ def _segments(self): ] return self._segments_list + @property + def tempfactors(self): + """Alias of ``bs`` matching the MDAnalysis ``tempfactors`` attribute. A property rather than an attribute set + in ``__init__`` so that it also exists on MolSys objects unpickled from older files.""" + return self.bs + @property def molsys(self): return self diff --git a/src/chilife/MolSysIC.py b/src/chilife/MolSysIC.py index e90c2e5d..b31fcf92 100644 --- a/src/chilife/MolSysIC.py +++ b/src/chilife/MolSysIC.py @@ -452,7 +452,7 @@ def nonbonded(self): dtype=int, ) - self._nonbonded.shape = (-1, 2) + self._nonbonded = self._nonbonded.reshape(-1, 2) return self._nonbonded diff --git a/src/chilife/SpinLabel.py b/src/chilife/SpinLabel.py index 721a0c98..d058b4df 100644 --- a/src/chilife/SpinLabel.py +++ b/src/chilife/SpinLabel.py @@ -38,7 +38,7 @@ def __init__(self, label, site=None, protein=None, chain=None, rotlib=None, **kw self.spin_atoms = self.spin_atoms[sa_mask] self.spin_weights = self.spin_weights[sa_mask] self.spin_idx = np.argwhere(np.isin(self.atom_names, self.spin_atoms)) - self.spin_idx.shape = -1 + self.spin_idx = self.spin_idx.reshape(-1) @property def spin_coords(self): diff --git a/src/chilife/SpinLigand.py b/src/chilife/SpinLigand.py index 234d422a..00c810dd 100644 --- a/src/chilife/SpinLigand.py +++ b/src/chilife/SpinLigand.py @@ -35,5 +35,4 @@ def __init__(self, res, site=None, protein=None, chain=None, rotlib=None, **kwar self.spin_atoms = self.atom_names[spin_atoms].copy() self.spin_weights = spin_weights - self.spin_idx = spin_atoms - self.spin_idx.shape = -1 \ No newline at end of file + self.spin_idx = spin_atoms.reshape(-1) \ No newline at end of file diff --git a/src/chilife/__init__.py b/src/chilife/__init__.py index 564aeaaa..256becbb 100644 --- a/src/chilife/__init__.py +++ b/src/chilife/__init__.py @@ -44,4 +44,4 @@ # SpinLabel = SpinLabel.SpinLabel # dSpinLabel = dSpinLabel.dSpinLabel -__version__ = "1.2.5" +__version__ = "1.3.0" diff --git a/src/chilife/chilife.py b/src/chilife/chilife.py index 3df8ea0d..9fbdb616 100644 --- a/src/chilife/chilife.py +++ b/src/chilife/chilife.py @@ -465,7 +465,7 @@ def create_library( ) if dihedrals.shape == (len(dihedrals),): - dihedrals.shape = (len(dihedrals), 1) + dihedrals = dihedrals.reshape(-1, 1) if weights is None: weights = np.ones(len(dihedrals)) diff --git a/src/chilife/io.py b/src/chilife/io.py index 6ce72e26..22f35b44 100644 --- a/src/chilife/io.py +++ b/src/chilife/io.py @@ -1250,8 +1250,8 @@ def write_frame(pdb_file: TextIO, atoms, frame=None, coords=None): "occupancies", np.ones(len(atoms.universe.atoms)) ) - if not hasattr(atoms.universe, "bfactors"): - atoms.universe.add_TopologyAttr("bfactors", np.ones(len(atoms.universe.atoms))) + if not hasattr(atoms.universe, "tempfactors"): + atoms.universe.add_TopologyAttr("tempfactors", np.ones(len(atoms.universe.atoms))) [ pdb_file.write( @@ -1263,7 +1263,7 @@ def write_frame(pdb_file: TextIO, atoms, frame=None, coords=None): atom.resnum, *coord, atom.occupancy, - atom.bfactor, + atom.tempfactor, atom.type, ) ) @@ -1468,7 +1468,7 @@ def write_atoms( for atom, coord in zip(atoms, coords): file.write( f"ATOM {atom.index + 1:5d} {atom.name:^4s} {atom.resname:3s} {'A':1s}{atom.resnum:4d} " - f"{coord[0]:8.3f}{coord[1]:8.3f}{coord[2]:8.3f}{atom.occupancy:6.2f}{atom.bfactor:6.2f} {atom.type:>2s} \n" + f"{coord[0]:8.3f}{coord[1]:8.3f}{coord[2]:8.3f}{atom.occupancy:6.2f}{atom.tempfactor:6.2f} {atom.type:>2s} \n" ) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..3d0561a8 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,7 @@ +import os +from pathlib import Path + +# Test modules reference data via relative paths such as "test_data/1ubq.pdb", +# and several load them at import time. Switch to the tests directory before +# collection so tests work no matter where pytest is launched from. +os.chdir(Path(__file__).parent) diff --git a/tests/test_MolSysIC.py b/tests/test_MolSysIC.py index 4d8c09ee..ad71d3f3 100644 --- a/tests/test_MolSysIC.py +++ b/tests/test_MolSysIC.py @@ -127,7 +127,7 @@ def test_set_dihedral2(): print("DSF") -@pytest.mark.parametrize(["inp", "ans"], zip(gd_kwargs, gd_ans)) +@pytest.mark.parametrize(["inp", "ans"], list(zip(gd_kwargs, gd_ans))) def test_get_dihedral(inp, ans): ubqIC = xl.MolSysIC.from_atoms(ubq) dihedral = ubqIC.get_dihedral(**inp) diff --git a/tests/test_ProteinUtils.py b/tests/test_ProteinUtils.py index e0a86b1b..80b1e741 100644 --- a/tests/test_ProteinUtils.py +++ b/tests/test_ProteinUtils.py @@ -578,8 +578,8 @@ def test_mkpep_template(): tphi = np.rad2deg(pep_IC.z_matrix[phi_idx, 2]) tpsi = np.rad2deg(pep_IC.z_matrix[psi_idx, 2]) - np.testing.assert_allclose(phi, tphi) - np.testing.assert_allclose(psi, tpsi) + np.testing.assert_allclose(phi, tphi, atol=1e-4) + np.testing.assert_allclose(psi, tpsi, atol=1e-4) def test_parsed_sequence(): @@ -597,7 +597,7 @@ def test_parsed_sequence(): s2rans = [f"test_data/s2rm{i + 1}.npy" for i in range(len(s2rkeys))] -@pytest.mark.parametrize("key, ans", zip(s2rkeys, s2rans)) +@pytest.mark.parametrize("key, ans", list(zip(s2rkeys, s2rans))) def test_smiles2residue(key, ans): m1 = chilife.smiles2residue(key, randomSeed=0) test_mask = np.argsort(m1.names) diff --git a/tests/test_Scoring.py b/tests/test_Scoring.py index cf5fee35..1e62ac9f 100644 --- a/tests/test_Scoring.py +++ b/tests/test_Scoring.py @@ -57,7 +57,7 @@ lj_rot_idx = [0, 5, 5] -@pytest.mark.parametrize(("func", "ans", "rot_idx"), zip(lj_funcs, lj_ans, lj_rot_idx)) +@pytest.mark.parametrize(("func", "ans", "rot_idx"), list(zip(lj_funcs, lj_ans, lj_rot_idx))) def test_lj(func, ans, rot_idx): f = chilife.ljEnergyFunc(func) RL = chilife.RotamerEnsemble("TRP", 28, protein, energy_func=f, eval_clash=True) diff --git a/tests/test_Topology.py b/tests/test_Topology.py index 1b400aad..52c0a62e 100644 --- a/tests/test_Topology.py +++ b/tests/test_Topology.py @@ -5,7 +5,18 @@ import MDAnalysis import chilife as xl from chilife.Topology import * -from MDAnalysis.topology.guessers import guess_angles, guess_dihedrals + +try: # MDAnalysis >= 2.8 + from MDAnalysis.guesser import DefaultGuesser + + def guess_angles(bonds): + return DefaultGuesser(None).guess_angles(bonds) + + def guess_dihedrals(angles): + return DefaultGuesser(None).guess_dihedrals(angles) + +except ImportError: # older MDAnalysis + from MDAnalysis.topology.guessers import guess_angles, guess_dihedrals ubq = xl.MolSys.from_pdb('test_data/1ubq.pdb', sort_atoms=True) mbp = MDAnalysis.Universe("test_data/2klf.pdb", in_memory=True) diff --git a/tests/test_chiLife.py b/tests/test_chiLife.py index 9702b920..25fd12f0 100755 --- a/tests/test_chiLife.py +++ b/tests/test_chiLife.py @@ -107,7 +107,7 @@ def test_get_lj_eps(): assert np.all(eps_params == ff.get_lj_eps(atom_names)) -@pytest.mark.parametrize("args, kws, expected", zip(args, kws, ans)) +@pytest.mark.parametrize("args, kws, expected", list(zip(args, kws, ans))) def test_distance_distribution(args, kws, expected): kws.setdefault("r", r) P_ans = expected @@ -178,7 +178,7 @@ def test_spin_populations(): # plt.show() -@pytest.mark.parametrize("cutoff, expected", zip([30, 0], sasa_ans)) +@pytest.mark.parametrize("cutoff, expected", list(zip([30, 0], sasa_ans))) def test_sas_res(cutoff, expected): sasres = chilife.get_sas_res(protein, cutoff) assert sasres == expected diff --git a/tests/test_io.py b/tests/test_io.py index 2164d8ab..41de0339 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -75,7 +75,7 @@ def test_fetch_AF_CIF(): fNames = ["1anf.pdb", "1omp.pdb", "3tu3.pdb"] -@pytest.mark.parametrize("pdbid, names", zip(IDs, fNames)) +@pytest.mark.parametrize("pdbid, names", list(zip(IDs, fNames))) def test_fetch2(pdbid, names): xl.fetch(pdbid, save=True) with open(f"test_data/m{names}", "r") as f: