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
# Create a filter, telling it to compress with zlib. filters = ts.Filters(complib='zlib') for amino_acid in (amino.amino_acids): table = fileh.create_table("/RotamerGroupTemplates", amino_acid, RotamerGroupTemplate, "Template for {res}".format(res=amino_acid)) # Get the record object associated with the table. group_template = table.row # Read in an appropriate topology file and create a molecular graph. filename = '/scratch/khs26/rotamer_lib_igb2/{res}/{res}/{res}/coords.prmtop'.format( res=amino_acid) topology = ra.read_topology(filename) mol_graph = ra.create_atoms_and_residues(topology) # Get the residue name for the first residue. res = next(residue for residue in mol_graph.residues.nodes() if residue.index == 1) # Get a list of dihedrals we are interested in for this residue. dihedrals = sorted([ k[1] for k in amino.def_parameters if k[0] == amino_acid and not ('C' in k[1] and 'CA' in k[1]) ]) # For each pair of atoms in a dihedral, find their highest-ranked neighbours for defining the dihedral angle. dihedral_atoms = {} dihedral_moving_atoms = {} for atom_pair in dihedrals:
# Create a filter, telling it to compress with zlib. filters = ts.Filters(complib='zlib') for amino_acid in (amino.amino_acids): table = fileh.create_table("/RotamerGroupTemplates", amino_acid, RotamerGroupTemplate, "Template for {res}".format(res=amino_acid)) # Get the record object associated with the table. group_template = table.row # Read in an appropriate topology file and create a molecular graph. filename = '/scratch/khs26/rotamer_lib_igb2/{res}/{res}/{res}/coords.prmtop'.format(res=amino_acid) topology = ra.read_topology(filename) mol_graph = ra.create_atoms_and_residues(topology) # Get the residue name for the first residue. res = next(residue for residue in mol_graph.residues.nodes() if residue.index == 1) # Get a list of dihedrals we are interested in for this residue. dihedrals = sorted([k[1] for k in amino.def_parameters if k[0] == amino_acid and not ('C' in k[1] and 'CA' in k[1])]) # For each pair of atoms in a dihedral, find their highest-ranked neighbours for defining the dihedral angle. dihedral_atoms = {} dihedral_moving_atoms = {} for atom_pair in dihedrals: atom0 = next(n for n in mol_graph.atoms.nodes() if n.name == atom_pair[0] and n.residue == res) atom1 = next(n for n in mol_graph.atoms.nodes() if n.name == atom_pair[1] and n.residue == res) atom_1 = next(atom for atom in chir.chiral_order(mol_graph.atoms, atom0, depth=2) if atom != atom1)
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