Skip to content

Commit

Permalink
Merge pull request #168 from Autodesk/topology_consistency
Browse files Browse the repository at this point in the history
Topology management
  • Loading branch information
avirshup authored Jun 30, 2017
2 parents 27046a4 + 1f0a804 commit 92bd7e1
Show file tree
Hide file tree
Showing 40 changed files with 1,678 additions and 613 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ exclude_lines =
pragma: no cover
def __repr__
def __str__
def _repr_markdown_
raise AssertionError
raise NotImplementedError
if PY2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ build
.cloudcomputecannon
__pycache__
.idea
.coverage*
.coverage
.coverage.*
codeship.aes
tokens
moldesign/_static_data/components.ci*
Expand Down
2 changes: 1 addition & 1 deletion deployment/codeship_runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e # fail immediately if any command fails


VERSION="${TESTENV}.py${PYVERSION}"
PYTESTFLAGS="-n 2 --spec --disable-warnings --durations=20 --junit-xml=/opt/reports/junit.${VERSION}.xml --timeout=1800 --tb=short"
PYTESTFLAGS="-n 2 --spec --durations=20 --junit-xml=/opt/reports/junit.${VERSION}.xml --timeout=3600 --tb=short"
if [ "${VERSION}" == "complete.py3" ]; then
PYTESTFLAGS="--cov moldesign ${PYTESTFLAGS}"
fi
Expand Down
474 changes: 474 additions & 0 deletions moldesign/_static_data/nist_atomic.yml

Large diffs are not rendered by default.

104 changes: 68 additions & 36 deletions moldesign/_tests/molecule_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,45 +63,68 @@ def random_atoms_from_3aid(pdb3aid):


@pytest.fixture(scope='session')
def create_small_molecule():
def cached_small_molecule():
mol = mdt.from_smiles('CNCOS(=O)C')
mol.positions += 0.001*np.random.random(mol.positions.shape)*u.angstrom # move out of minimum
return mol


@pytest.fixture
def small_molecule(create_small_molecule):
return create_small_molecule.copy()
def small_molecule(cached_small_molecule):
return cached_small_molecule.copy()


@pytest.fixture()
def benzene():
@pytest.fixture(scope='session')
def cached_benzene():
return mdt.from_smiles('c1ccccc1')


@pytest.fixture
def benzene(cached_benzene):
return cached_benzene.copy()


@typedfixture('molecule')
def h2():
atom1 = mdt.Atom('H')
atom1.x = 0.5 * u.angstrom
atom2 = mdt.Atom(atnum=1)
atom2.position = [-0.5, 0.0, 0.0] * u.angstrom
h2 = mdt.Molecule([atom1, atom2], name='h2')
atom1.bond_to(atom2, 1)
return h2
mol = mdt.Molecule([mdt.Atom('H1'),
mdt.Atom('H2')])
mol.atoms[0].x = 0.5 * u.angstrom
mol.atoms[1].x = -0.25 * u.angstrom
mol.atoms[0].bond_to(mol.atoms[1], 1)
return mol


@pytest.fixture
def ethylene():
@typedfixture('molecule')
def heh_plus():
mol = mdt.Molecule([mdt.Atom('H'),
mdt.Atom('He')])
mol.atoms[1].z = 1.0 * u.angstrom
mol.charge = 1 * u.q_e
mol.atoms[0].bond_to(mol.atoms[1], 1)
return mol


@pytest.fixture(scope='session')
def cached_ethylene():
return mdt.from_smiles('C=C')


@pytest.fixture
def ethylene(cached_ethylene):
return cached_ethylene.copy()


@pytest.fixture(scope='session')
def cached_pdb1yu8():
return mdt.read(get_data_path('1yu8.pdb'))

@pytest.fixture
def pdb1yu8():
return mdt.read(get_data_path('1yu8.pdb'))


@pytest.fixture()
def mol_from_xyz():
@pytest.fixture(scope='session')
def cached_mol_from_xyz():
return mdt.read("""43
c1.pdb
C -1.21700 1.04300 2.45300
Expand Down Expand Up @@ -150,8 +173,13 @@ def mol_from_xyz():
""", format='xyz')


@pytest.fixture()
def mol_from_sdf():
@pytest.fixture
def mol_from_xyz(cached_mol_from_xyz):
return cached_mol_from_xyz.copy()


@pytest.fixture(scope='session')
def cached_mol_from_sdf():
return mdt.read("""
OpenBabel02271712493D
Expand Down Expand Up @@ -181,6 +209,10 @@ def mol_from_sdf():
$$$$
""", format='sdf')

@pytest.fixture
def mol_from_sdf(cached_mol_from_sdf):
return cached_mol_from_sdf.copy()


@typedfixture('molecule')
def nucleic():
Expand All @@ -193,64 +225,64 @@ def nucleic():
# Molecules with forcefields assigned - these use a session-scoped constructor w/ a copy factory

@pytest.fixture(scope='session')
def create_parameterize_zeros(create_small_molecule):
return _param_small_mol(create_small_molecule.copy(), 'zero')
def cached_mol_parameterized_with_zeros(cached_small_molecule):
return _param_small_mol(cached_small_molecule.copy(), 'zero')


@typedfixture('hasmodel')
def parameterize_zeros(create_parameterize_zeros):
return create_parameterize_zeros.copy()
def mol_with_zerocharge_params(cached_mol_parameterized_with_zeros):
return cached_mol_parameterized_with_zeros.copy()


@pytest.fixture(scope='session')
def create_parameterize_am1bcc(create_small_molecule):
def cached_mol_parameterized_with_am1bcc(cached_small_molecule):
""" We don't use this fixture directly, rather use another fixture that copies these results
so that we don't have to repeatedly call tleap/antechamber
"""
return _param_small_mol(create_small_molecule.copy(), 'am1-bcc')
return _param_small_mol(cached_small_molecule.copy(), 'am1-bcc')


@typedfixture('hasmodel')
def parameterize_am1bcc(create_parameterize_am1bcc):
return create_parameterize_am1bcc.copy()
def mol_with_am1bcc_params(cached_mol_parameterized_with_am1bcc):
return cached_mol_parameterized_with_am1bcc.copy()


@pytest.fixture(scope='session')
def create_gaff_model_gasteiger(create_small_molecule):
def cached_mol_parameterized_with_gasteiger(cached_small_molecule):
""" We don't use this fixture directly, rather use another fixture that copies these results
so that we don't have to repeatedly call tleap/antechamber
"""
mol = create_small_molecule.copy()
mol = cached_small_molecule.copy()
mol.set_energy_model(mdt.models.GaffSmallMolecule, partial_charges='gasteiger')
mol.energy_model.prep()
return mol


@typedfixture('hasmodel')
def gaff_model_gasteiger(create_gaff_model_gasteiger):
return create_gaff_model_gasteiger.copy()
def mol_with_gast_params(cached_mol_parameterized_with_gasteiger):
return cached_mol_parameterized_with_gasteiger.copy()


def _param_small_mol(create_small_molecule, chargemodel):
mol = create_small_molecule.copy()
def _param_small_mol(cached_small_molecule, chargemodel):
mol = cached_small_molecule.copy()
params = mdt.create_ff_parameters(mol, charges=chargemodel, baseff='gaff2')
params.assign(mol)
mol.set_energy_model(mdt.models.ForceField)
return mol


@pytest.fixture(scope='session')
def create_protein_default_amber_forcefield(pdb1yu8):
def cached_protein_with_default_amber_ff(cached_pdb1yu8):
""" We don't use this fixture directly, rather use another fixture that copies these results
so that we don't have to repeatedly call tleap/antechamber
"""
mol = pdb1yu8
mol = cached_pdb1yu8
ff = mdt.forcefields.DefaultAmber()
newmol = ff.create_prepped_molecule(mol)
newmol.set_energy_model(mdt.models.ForceField)
return newmol


@typedfixture('hasmodel')
def protein_default_amber_forcefield(create_protein_default_amber_forcefield):
return create_protein_default_amber_forcefield.copy()
def protein_default_amber_forcefield(cached_protein_with_default_amber_ff):
return cached_protein_with_default_amber_ff.copy()
3 changes: 1 addition & 2 deletions moldesign/_tests/object_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

from .molecule_fixtures import *

registered_types = {}
registered_types.update(molecule_standards)
registered_types = {key:val[:] for key,val in molecule_standards.items()}

def typedfixture(*types, **kwargs):
"""This is a decorator that lets us associate fixtures with one or more arbitrary types.
Expand Down
8 changes: 7 additions & 1 deletion moldesign/_tests/test_atom_bond_computed_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import moldesign as mdt
from moldesign import units as u

from .test_ambertools_xface import protein_default_amber_forcefield, pdb1yu8
from .molecule_fixtures import *
from . import helpers
from .test_qm_xfaces import h2_rhfwfn



def test_forcefield_atom_term_access(protein_default_amber_forcefield):
mol = protein_default_amber_forcefield
for atom in mol.atoms:
Expand Down Expand Up @@ -61,6 +62,11 @@ def test_atom_property_access_to_mulliken_charges(h2_rhfwfn):
assert abs(atom.properties.mulliken) <= 1e-5 * u.q_e


def test_atomic_forces(h2_rhfwfn):
mol = h2_rhfwfn
helpers.assert_almost_equal(mol.atoms[0].force, -mol.atoms[1].force)


def test_atom_properties_are_empty_dict_if_nothings_computed(h2):
empty = mdt.utils.DotDict()
for atom in h2.atoms:
Expand Down
5 changes: 4 additions & 1 deletion moldesign/_tests/test_atom_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def test_pairwise_distance_arrays(f1, f2, request):
o1 = request.getfixturevalue(f1)
o2 = request.getfixturevalue(f2)

array = o1.calc_distance_array(o2)
if isinstance(o1, mdt.Atom):
array = np.array([o1.calc_distance(o2)])
else:
array = o1.calc_distance_array(o2)

if o1.num_atoms * o2.num_atoms > 250: # stochastically test larger matrices
pairs = ((random.randrange(0, o1.num_atoms), random.randrange(0, o2.num_atoms))
Expand Down
Loading

0 comments on commit 92bd7e1

Please sign in to comment.