def get_random_configuration(self): """set coordinates before calling BH etc.""" """ returns a 1-D numpy array of length 3xNatoms """ # using pele.amber.read_amber and inpcrd from pele.amber.read_amber import read_amber_coords coords = read_amber_coords(self.inpcrdFname) print "amberSystem> Number of coordinates:", len(coords) coords = np.reshape(np.transpose(coords), len(coords), 1) # -- OpenMM # from simtk.unit import angstrom as openmm_angstrom ## using pdb # from simtk.openmm.app import pdbfile as openmmpdbReader # pdb = openmmpdbReader.PDBFile('coords.pdb') # todo: coords.pdb is hardcoded # coords = pdb.getPositions() / openmm_angstrom # coords = np.reshape(np.transpose(coords), 3*len(coords),1 ) ## using input inpcrd # from simtk.openmm.app import AmberInpcrdFile # inpcrd = AmberInpcrdFile( self.inpcrdFname ) # coords = inpcrd.getPositions() / openmm_angstrom # coords = np.reshape(np.transpose(coords), 3*len(coords),1 ) return coords
def measure_dihedral(coords, atoms): indices = [3 * atom + k for atom in atoms for k in range(3)] coords_0 = coords[indices[0:3]] coords_1 = coords[indices[3:6]] coords_2 = coords[indices[6:9]] coords_3 = coords[indices[9:12]] b1 = coords_1 - coords_0 b2 = coords_2 - coords_1 b3 = coords_3 - coords_2 b2_b3 = np.cross(b2, b3) b1_b2 = np.cross(b1, b2) angle = np.arctan2( np.linalg.norm(b2) * np.dot(b1, b2_b3), np.dot(b1_b2, b2_b3)) return angle if __name__ == "__main__": import pele.amber.read_amber as amber import playground.group_rotation.amino_acids as amino topology_data = amber.read_topology("/home/khs26/coords.prmtop") parsed = amber.create_atoms_and_residues(topology_data) test_params = amber.group_rotation_dict(parsed, amino.def_parameters) test_coords = np.array( amber.read_amber_coords("/home/khs26/coords.inpcrd")) testGR = GroupRotation(test_params) pre_coords = test_coords.copy() result = testGR.takeStep(test_coords) print test_coords - pre_coords
attribute_variance[group] = ((i) * attribute_variance[group] + diff**2) / float(i + 1) return attribute_average, attribute_variance def measure_dihedral(coords, atoms): indices = [3 * atom + k for atom in atoms for k in range(3)] coords_0 = coords[indices[0:3]] coords_1 = coords[indices[3:6]] coords_2 = coords[indices[6:9]] coords_3 = coords[indices[9:12]] b1 = coords_1 - coords_0 b2 = coords_2 - coords_1 b3 = coords_3 - coords_2 b2_b3 = np.cross(b2, b3) b1_b2 = np.cross(b1, b2) angle = np.arctan2(np.linalg.norm(b2) * np.dot(b1, b2_b3), np.dot(b1_b2, b2_b3) ) return angle if __name__ == "__main__": import pele.amber.read_amber as amber import playground.group_rotation.amino_acids as amino topology_data = amber.read_topology("/home/khs26/coords.prmtop") parsed = amber.create_atoms_and_residues(topology_data) test_params = amber.group_rotation_dict(parsed, amino.def_parameters) test_coords = np.array(amber.read_amber_coords("/home/khs26/coords.inpcrd")) testGR = GroupRotation(test_params) pre_coords = test_coords.copy() result = testGR.takeStep(test_coords) print(test_coords-pre_coords)
attribute_variance[group] = ((i) * attribute_variance[group] + diff**2) / float(i + 1) return attribute_average, attribute_variance def measure_dihedral(coords, atoms): indices = [3 * atom + k for atom in atoms for k in range(3)] coords_0 = coords[indices[0:3]] coords_1 = coords[indices[3:6]] coords_2 = coords[indices[6:9]] coords_3 = coords[indices[9:12]] b1 = coords_1 - coords_0 b2 = coords_2 - coords_1 b3 = coords_3 - coords_2 b2_b3 = np.cross(b2, b3) b1_b2 = np.cross(b1, b2) angle = np.arctan2(np.linalg.norm(b2) * np.dot(b1, b2_b3), np.dot(b1_b2, b2_b3) ) return angle if __name__ == "__main__": import pele.amber.read_amber as amber import playground.group_rotation.amino_acids as amino topology_data = amber.read_topology("/home/khs26/coords.prmtop") parsed = amber.create_atoms_and_residues(topology_data) test_params = amber.group_rotation_dict(parsed, amino.def_parameters) test_coords = np.array(amber.read_amber_coords("/home/khs26/coords.inpcrd")) testGR = GroupRotation(test_params) pre_coords = test_coords.copy() result = testGR.takeStep(test_coords) print test_coords-pre_coords
for dihedral in unmapped_dihedrals: # We need to convert "N-1" to the N neighbouring "C0". The others can be converted using the map. atom_map = residue_atom_map[residue] mapped_dihedral = [[nb for nb in nx.neighbors(residue.molecule.atoms, atom_map["C0"]) if nb.element == "N"][0] if atom_name == "N-1" else atom_map[atom_name] for atom_name in dihedral] mapped_dihedrals.append(mapped_dihedral) dihedral_dict[residue] = mapped_dihedrals return dihedral_dict if __name__ == "__main__": import os.path import numpy as np from playground.rotamer.measure_dihedral import dihedrals_with_symmetry import cProfile # pr = cProfile.Profile() # pr.enable() topology_data = amber.read_topology(os.path.normpath("/home/khs26/flu.prmtop")) coords = np.array(amber.read_amber_coords(os.path.normpath("/home/khs26/flu.inpcrd"))).reshape((-1, 3)) molecule = amber.create_molecule(topology_data) ress, maps = molecule.identify_residues() dihedrals = [] for v in map_dihedrals(ress, maps).values(): for dihedral in v: dihedrals.append(Dihedral(dihedral)) for dihe in sorted(dihedrals, key=lambda x: x.residue.index): if dihe.residue.identity in symmetric_atoms: print dihe.residue, dihe.atoms, dihe.residue.atoms print "Angle:", dihe.measure_dihedral(coords) * 180.0 / np.pi # pr.disable() # pr.print_stats('cumulative')