def parse_prmtop(self): self.prmtop_parsed = parse_topology_file(self.prmtopFname) atoms = self.prmtop_parsed.atoms.nodes() atoms = sorted(atoms, key=lambda a: a.index) self.atom_names = [a.element for a in atoms] self.bonds = [(a1.index, a2.index) for a1, a2 in self.prmtop_parsed.atoms.edges_iter()]
def write_chirality_file(input_filename, output_filename, human_readable_filename): molecule = ra.parse_topology_file(input_filename) atoms = molecule.atoms chiral_cands = chiral_candidates(atoms) multi_bonds(atoms) chiral_centres = {} for i, chiral_atom in enumerate(chiral_cands): ordered = chiral_order(atoms, chiral_atom) if len(ordered) == 4: chiral_centres[chiral_atom] = ordered with open(output_filename, "w") as output_file: for atom in sorted(chiral_centres.keys(), cmp=lambda x, y: cmp(x.index, y.index)): # Write out the list of chiral atoms and their CIP-ranked neighbours. output_string = "{0:>8d}{1:>8d}{2:>8d}{3:>8d}{4:>8d}\n".format(atom.index + 1, *[other_atom.index + 1 for other_atom in chiral_centres[atom]]) output_file.write(output_string) with open(human_readable_filename, "w") as human_file: human_file.write("Atom names given below are in the format: <index (from 0)> <element> <atom name>\n") human_file.write("e.g.: 12 C CA is the 13th atom, is a carbon and is named \"CA\"\n\n") output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format("central atom", "top ranked", "2nd ranked", "3rd ranked", "lowest ranked") human_file.write(output_string) output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format("============", "==========", "==========", "==========", "=============") human_file.write(output_string) for atom in sorted(chiral_centres.keys(), cmp=lambda x, y: cmp(x.index, y.index)): # Write out the list of chiral atoms and their CIP-ranked neighbours - but this time readable for humans. output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format(str(atom), *[str(other_atom) for other_atom in chiral_centres[atom]]) human_file.write(output_string)
def write_cis_trans_file(input_filename, output_filename): molecule = ra.parse_topology_file(input_filename) atoms = molecule.atoms # for atom in atoms: # print atom.residue multi_bonds(atoms) with open(output_filename, "w") as output_file: for bond in sorted(peptide_bonds(atoms), cmp=lambda x, y: cmp(x[0].index, y[0].index)): # Write out the list of atoms in peptide bonds (O - C - N - H). output_string = "{0:>8d}{1:>8d}{2:>8d}{3:>8d}\n".format(*map(lambda x: x.index + 1, bond)) output_file.write(output_string)
def write_chirality_file(input_filename, output_filename, human_readable_filename): molecule = ra.parse_topology_file(input_filename) atoms = molecule.atoms chiral_cands = chiral_candidates(atoms) multi_bonds(atoms) chiral_centres = {} for i, chiral_atom in enumerate(chiral_cands): ordered = chiral_order(atoms, chiral_atom) if len(ordered) == 4: chiral_centres[chiral_atom] = ordered with open(output_filename, "w") as output_file: for atom in sorted(chiral_centres.keys(), cmp=lambda x, y: cmp(x.index, y.index)): # Write out the list of chiral atoms and their CIP-ranked neighbours. output_string = "{0:>8d}{1:>8d}{2:>8d}{3:>8d}{4:>8d}\n".format( atom.index + 1, *[other_atom.index + 1 for other_atom in chiral_centres[atom]]) output_file.write(output_string) with open(human_readable_filename, "w") as human_file: human_file.write( "Atom names given below are in the format: <index (from 0)> <element> <atom name>\n" ) human_file.write( "e.g.: 12 C CA is the 13th atom, is a carbon and is named \"CA\"\n\n" ) output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format( "central atom", "top ranked", "2nd ranked", "3rd ranked", "lowest ranked") human_file.write(output_string) output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format( "============", "==========", "==========", "==========", "=============") human_file.write(output_string) for atom in sorted(chiral_centres.keys(), cmp=lambda x, y: cmp(x.index, y.index)): # Write out the list of chiral atoms and their CIP-ranked neighbours - but this time readable for humans. output_string = "{0:^16s}{1:^16s}{2:^16s}{3:^16s}{4:^16s}\n".format( str(atom), *[str(other_atom) for other_atom in chiral_centres[atom]]) human_file.write(output_string)