Esempio n. 1
0
def test_create_database_3() -> None:
    """Test the backwards compatiblity of pre-``0.3`` databases."""
    shutil.copytree(DB_PATH_OLD3, DB_PATH_NEW3)
    db = Database(DB_PATH_NEW3)

    with db.hdf5('r', libver='latest') as f:
        pdb = PDBContainer.from_hdf5(f['ligand'])
        mol_list = pdb.to_molecules()

    mol_list_ref = []
    files = ('C3H7O1.pdb', 'C2H5O1.pdb', 'C1H3O1.pdb')
    for _path in files:
        path = str(DB_PATH_NEW3 / _path)
        mol_list_ref.append(readpdb(path))

    # Compare molecules
    for mol1, mol2 in zip(mol_list, mol_list_ref):
        msg = f'{mol1.get_formula()} & {mol2.get_formula()}'
        np.testing.assert_allclose(mol1,
                                   mol2,
                                   rtol=0,
                                   atol=10**-2,
                                   err_msg=msg)
        np.testing.assert_array_equal(mol1.bond_matrix(),
                                      mol2.bond_matrix(),
                                      err_msg=msg)

    with db.hdf5('r', libver='latest') as f:
        group = f['ligand']
        pdb.validate_hdf5(group)
Esempio n. 2
0
def test_call() -> None:
    """Tests for :meth:`MolDissociater.__call__`."""
    mol_iterator = dissociate_ligand(MOL, lig_count=2, core_index=CORE_IDX)
    filename = str(PATH / '{}.pdb')
    for mol in mol_iterator:
        name = mol.properties.core_topology
        mol_ref = readpdb(filename.format(name))
        xyz = mol.as_array()
        ref = mol_ref.as_array()
        np.testing.assert_allclose(xyz, ref)
Esempio n. 3
0
 def recreate_molecule(self) -> Molecule:
     """Create a |Molecule| instance from ``"$JN.pdb"``."""
     pdb_file = self['$JN.pdb']
     try:
         return readpdb(self['$JN.pdb'])
     except AttributeError as ex:
         # readpdb() will pass None to from_rdmol(), resulting in an AttributeError down the line
         raise FileError(
             f"Failed to parse the content of ...{os.sep}{pdb_file!r}"
         ) from ex
Esempio n. 4
0
    def _prepare_pdb(self, stream):
        """Fill :attr:`MatchJob.pdb` with a string-representation of the .pdb file."""
        conitions = {'filename' in self.settings.input, bool(self.molecule)}
        if not any(conitions):
            raise JobError("Ambiguous input: either `molecule` or "
                           "`settings.input.filename` must be specified")
        if all(conitions):
            raise JobError(
                "Ambiguous input: `molecule` and "
                "`settings.input.filename` cannot be both specified")

        if self.molecule:
            writepdb(self.molecule, stream)
        else:
            filename = self.settings.input.pop('filename')
            writepdb(readpdb(filename), stream)

        self.pdb: str = stream.getvalue()
Esempio n. 5
0
def test_call_no_core() -> None:
    """Tests for :meth:`MolDissociater.__call__` where `core == lig`."""
    lig_idx = [148, 190, 224, 294]
    dissociate = MolDissociater(MOL, lig_idx, ligand_count=1)
    pair1 = dissociate.get_pairs_closest(LIG_IDX, n_pairs=1)
    pair2 = dissociate.get_pairs_closest(LIG_IDX, n_pairs=2)

    dissociate.ligand_count = 2
    pair3 = dissociate.get_pairs_closest(LIG_IDX, n_pairs=1)
    pair4 = dissociate.get_pairs_closest(LIG_IDX, n_pairs=2)

    pairs = (pair1, pair2, pair3, pair4)
    for i, pair in enumerate(pairs, 1):
        ref = np.load(PATH / f'call_no_core_{i}.npy')
        np.testing.assert_array_equal(pair, ref)

    mol_iterator = dissociate_ligand(MOL, lig_count=1, core_index=lig_idx)
    filename = str(PATH / '{}.pdb')
    for mol in mol_iterator:
        name = mol.properties.core_topology
        mol_ref = readpdb(filename.format(name))
        xyz = mol.as_array()
        ref = mol_ref.as_array()
        np.testing.assert_allclose(xyz, ref)
Esempio n. 6
0
"""Tests for :mod:`nanoCAT.bde.guess_core_dist`."""

from pathlib import Path

from scm.plams import readpdb, Molecule
from assertionlib import assertion

from nanoCAT.bde.guess_core_dist import guess_core_core_dist

PATH = Path('tests') / 'test_files'
with open(PATH / 'mol.pdb', 'r') as f:
    MOL: Molecule = readpdb(f)


def test_guess_core_core_dist() -> None:
    """Tests for :func:`nanoCAT.bde.guess_core_dist.guess_core_core_dist`."""
    dist = guess_core_core_dist(MOL, 'Cd')
    ref = 5.175623211939212
    assertion.allclose(dist, ref)
Esempio n. 7
0
    :annotation: : pathlib.Path = ...
.. autodata:: HDF5_READ
    :annotation: : pathlib.Path = ...

"""

from typing import Tuple
from pathlib import Path

from scm.plams import readpdb, Molecule

from .pdb_array import PDBContainer
from .data import PDB_TUPLE

__all__ = ['MOL_TUPLE', 'MOL', 'PDB', 'HDF5_TMP', 'HDF5_READ']

#: A tuple of PLAMS Molecules.
MOL_TUPLE: Tuple[Molecule, ...] = tuple(readpdb(f) for f in PDB_TUPLE)

#: A PLAMS Molecule.
MOL: Molecule = MOL_TUPLE[0]

#: A PDBContainer.
PDB: PDBContainer = PDBContainer.from_molecules(MOL_TUPLE)

#: A path to a temporary (to-be created) hdf5 file.
HDF5_TMP = Path('tests') / 'test_files' / '.structures.hdf5'

#: A path to a read-only hdf5 file.
HDF5_READ = Path('tests') / 'test_files' / 'database' / 'structures.hdf5'