def test_two_molecules(individual, protein, ligand): individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.genes['Protein'] = Molecule(parent=individual, path=datapath(protein)) individual.__ready__() individual.__expression_hooks__() with expressed(individual): assert individual.expressed is True
def test_rotamers(individual, path, position, seed, restype, original_chis, new_chis): rotamer = rotamers(individual, path, position, seed) residue = rotamer.residues[('Molecule', position)] # Cache initial coordinates for the residue and ALL the alpha carbons in the protein alpha_carbons_coords = [a.xformCoord() for a in residue.molecule.atoms if a.name == 'CA'] residue_coords = [a.xformCoord() for a in residue.atoms] with expressed(individual): assert residue.id.position == position assert residue.type == restype assert [a.xformCoord() for a in residue.molecule.atoms if a.name == 'CA'] == alpha_carbons_coords assert [a.xformCoord() for a in residue.atoms] != residue_coords for real, torsion in zip(original_chis, residue._rotamer_torsions): assert abs(real - torsion.chi) < 0.001 for real, computed_modified in zip(new_chis, rotamer.all_chis(residue)): assert abs(real - computed_modified) < 0.001 # Check everything is back in place! for original, reverted in zip([a.xformCoord() for a in residue.atoms], residue_coords): for a, b in zip(original, reverted): assert abs(a - b) < 0.001 for original, reverted in zip([a.xformCoord() for a in residue.molecule.atoms if a.name == 'CA'], alpha_carbons_coords): for a, b in zip(original, reverted): assert abs(a - b) < 0.001 for original, reverted in zip(original_chis, rotamer.all_chis(residue)): assert abs(original - reverted) < 0.001
def test_nwchem(individual, ligand, energy): individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.__ready__() individual.__expression_hooks__() objective = NWChem(targets=['Ligand'], title='test', weight=-1.0) with expressed(individual): assert abs(energy - objective.evaluate(individual)) < 0.0001
def test_vina(individual, protein, ligand, affinity): individual.genes['Protein'] = Molecule(parent=individual, path=datapath(protein)) individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.__ready__() individual.__expression_hooks__() objective = Vina(weight=-1.0) with expressed(individual): assert affinity == objective.evaluate(individual)
def energy(individual, path): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Energy() with expressed(individual): return objective.evaluate(individual)
def test_molecule(individual, path, atoms): absolute_path = os.path.abspath(datapath(path)) individual.genes['Molecule'] = Molecule(parent=individual, path=absolute_path) individual.__ready__() individual.__expression_hooks__() assert individual.genes['Molecule'].compound.mol.numAtoms == atoms assert individual.genes['Molecule'].compound.mol.openedAs[0] == absolute_path with expressed(individual): assert individual.expressed is True
def interactions(individual, path, which): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() kwargs = dict(probes=['Molecule'], radius=10 * random(), which=which) objective = Contacts(**kwargs) with expressed(individual): return objective.evaluate(individual)
def test_torsion(individual, path, angle, bonds, rotatable, distance): torsion = torsions(individual, path, angle) with expressed(individual): assert individual.genes['Molecule'].compound.mol.numBonds == bonds atom1 = individual.genes['Molecule'].compound.mol.atoms[0] point = individual.genes['Molecule'].compound.mol.atoms[-1].xformCoord( ) assert len(list( torsion.rotatable_bonds)) == rotatable == torsion.max_bonds == len( torsion.allele) assert Distance._distance(atom1, point) == distance
def test_search_translation(individual, path, target, radius, rotate): search = search_gene(individual, path, target=target, radius=radius, rotate=rotate) target_atom = individual.find_molecule(search.target.molecule).find_atom( search.target.atom) original_position = target_atom.xformCoord() with expressed(individual): expressed_position = target_atom.xformCoord() assert original_position.distance(expressed_position) <= radius
def test_coordination_uncorrected(individual, path, metal, ligands, geometry, score): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Coordination(probe=('Molecule', metal), residues=[('Molecule', '*')], atom_elements=('C N O S'.split()), geometry=geometry, weight=-1.0) with expressed(individual): sphere = objective.coordination_sphere(individual)[:objective.n_vertices] assert len(sphere) == len(ligands) assert sorted(ligands) == sorted([a.serialNumber for (d, a) in sphere]) fitness = objective.evaluate(individual) assert abs(fitness - score) < 0.0001
def test_backbone_torsion(individual, path, angle, distance): torsion = torsions(individual, path, angle, rotatable_atom_types=(), rotatable_atom_names=('CA', )) with expressed(individual): assert all('CA' in [a.name for a in br.bond.atoms] for br in torsion.rotatable_bonds) atom1 = individual.genes['Molecule'].compound.mol.atoms[0] point = individual.genes['Molecule'].compound.mol.atoms[-1].xformCoord( ) assert abs(Distance._distance(atom1, point) - distance) < 0.0001
def test_topology(individual, path, atoms, bonds, residues): individual.genes['Molecule'] = Molecule(parent=individual, path=datapath(path)) individual.__ready__() individual.__expression_hooks__() objective = Energy() with expressed(individual): molecules = objective.molecules(individual) topology = objective.chimera_molecule_to_openmm_topology(*molecules) assert topology.getNumAtoms() == sum(m.numAtoms for m in molecules) assert len(list(topology.bonds())) == sum(m.numBonds for m in molecules) assert topology.getNumResidues() == sum(m.numResidues for m in molecules)
def test_trajectory(individual, mol_path, trajectory_path, frame, max_frame): gene = trajectory_setup(individual, mol_path, trajectory_path, frame, max_frame) traj = mdtraj.load_frame(datapath(trajectory_path), frame, top=datapath(mol_path)) m = gene.molecule with expressed(individual): assert np.abs((m.compound.mol.activeCoordSet.xyzArray() - m.xyz()) < 0.001).all() assert np.abs( (m.compound.mol.atomCoordinatesArray() - m.xyz()) < 0.001).all() assert np.abs((m.xyz() - (traj.xyz[0] * 10)) < 0.001).all() assert gene.topology.n_atoms == traj.top.n_atoms assert gene.topology.n_bonds == traj.top.n_bonds assert gene.topology.n_residues == traj.top.n_residues
def dsx(individual, protein, ligand, **kwargs): individual.genes['Protein'] = Molecule(parent=individual, path=datapath(protein)) individual.genes['Ligand'] = Molecule(parent=individual, path=datapath(ligand)) individual.__ready__() individual.__expression_hooks__() options = dict(weight=-1.0, terms=[True, False, False, True, False], proteins=['Protein'], ligands=['Ligand'], sorting=1, cofactor_mode=0, with_metals=False) options.update(kwargs) objective = DSX(**options) with expressed(individual): return objective.evaluate(individual)
def test_normalmodes_prody(individual, path, target, group_by): nma = nma_gene(individual, path, target=target, group_by=group_by, n_samples=500) observed_rmsds = [] for sample in nma.NORMAL_MODES_SAMPLES: nma.allele = sample with expressed(individual): observed_rmsd = sqrmsd(nma._original_coords, nma.molecule.atomCoordinatesArray()) assert 0 < observed_rmsd observed_rmsds.append(observed_rmsd) assert np.isclose(np.mean(observed_rmsds), nma.rmsd * nma.rmsd, rtol=0.1, atol=0.001)
def test_molecule(individual, individual2, path1, path2, threshold): absolute_path1 = os.path.abspath(datapath(path1)) absolute_path2 = os.path.abspath(datapath(path2)) individual.genes['Molecule'] = Molecule(parent=individual, path=absolute_path1) individual.__ready__() individual.__expression_hooks__() individual2.genes['Molecule'] = Molecule(parent=individual2, path=absolute_path2) individual2.__ready__() individual2.__expression_hooks__() with expressed(individual, individual2): sqrmsd = _rmsd_squared( individual.genes['Molecule']._expressed_coordinates, individual2.genes['Molecule']._expressed_coordinates) assert abs(sqrmsd - threshold * threshold) < 0.01 assert rmsd(individual, individual2, ['Molecule'], threshold)
def run(): torsions(individual, path, angle) with expressed(individual): pass
def run(): rotamers(individual, path, position, seed) with expressed(individual): pass