De-lint output.py.

Public methods/members changed; dependencies checked via Google.
This commit is contained in:
Nathan Baker
2020-05-25 08:24:54 -07:00
parent 3342d3418c
commit f38faaed97
3 changed files with 365 additions and 312 deletions

View File

@@ -184,8 +184,7 @@ class Molecular_container:
filename = os.path.join('%s_%s.pka' % (self.name, filename = os.path.join('%s_%s.pka' % (self.name,
self.version.parameters.output_file_tag)) self.version.parameters.output_file_tag))
propka.output.write_pka(self, self.version.parameters, filename=filename, propka.output.write_pka(self, self.version.parameters, filename=filename,
conformation='AVR', reference=reference, conformation='AVR', reference=reference)
direction=direction, options=options)
def get_folding_profile(self, conformation='AVR', reference="neutral", def get_folding_profile(self, conformation='AVR', reference="neutral",
grid=[0., 14., 0.1]): grid=[0., 14., 0.1]):

View File

@@ -1,397 +1,451 @@
"""Output routines."""
from __future__ import division from datetime import date
from __future__ import print_function from propka.lib import info
import sys
import propka.lib
from propka.lib import info, warning
def printHeader(): def print_header():
"""Print header section of output."""
str_ = "%s\n" % get_propka_header()
str_ += "%s\n" % get_references_header()
str_ += "%s\n" % get_warning_header()
info(str_)
def write_pdb(protein, pdbfile=None, filename=None, include_hydrogens=False,
_=None):
"""Write a residue to the new PDB file.
Args:
protein: protein object
pdbfile: PDB file
filename: file to write to
include_hydrogens: Boolean indicating whether to include hydrogens
options: options object
""" """
prints the header section if pdbfile is None:
"""
str = "%s\n" % ( getPropkaHeader() )
str += "%s\n" % ( getReferencesHeader() )
str += "%s\n" % ( getWarningHeader() )
info(str)
def writePDB(protein, file=None, filename=None, include_hydrogens=False, options=None):
"""
Write the residue to the new pdbfile
"""
if file == None:
# opening file if not given # opening file if not given
if filename == None: if filename is None:
filename = "%s.pdb" % (protein.name) filename = "%s.pdb" % (protein.name)
file = open(filename, 'w') # TODO - this would be better as a context manager
pdbfile = open(filename, 'w')
info("writing pdbfile %s" % (filename)) info("writing pdbfile %s" % (filename))
close_file = True close_file = True
else: else:
# don't close the file, it was opened in a different place # don't close the file, it was opened in a different place
close_file = False close_file = False
numb = 0 numb = 0
for chain in protein.chains: for chain in protein.chains:
for residue in chain.residues: for residue in chain.residues:
if residue.res_name not in ["N+ ", "C- "]: if residue.res_name not in ["N+ ", "C- "]:
for atom in residue.atoms: for atom in residue.atoms:
if include_hydrogens == False and atom.name[0] == "H": if (not include_hydrogens) and atom.name[0] == "H":
""" don't print """ # don't print
pass
else: else:
numb += 1 numb += 1
line = atom.make_pdb_line2(numb=numb) line = atom.make_pdb_line2(numb=numb)
line += "\n" line += "\n"
file.write(line) pdbfile.write(line)
if close_file:
if close_file == True: pdbfile.close()
file.close()
def writePKA(protein, parameters, filename=None, conformation ='1A',reference="neutral", direction="folding", verbose=False, options=None): def write_pka(protein, parameters, filename=None, conformation='1A',
""" reference="neutral", _="folding", verbose=False,
Write the pka-file based on the given protein __=None):
"""Write the pKa-file based on the given protein.
Args:
protein: protein object
filename: output file name
conformation: TODO - figure this out
reference: reference state
_: "folding" or other
verbose: Boolean flag for verbosity
__: options object
""" """
# TODO - the code immediately overrides the verbose argument; why?
verbose = True verbose = True
if filename == None: if filename is None:
filename = "%s.pka" % (protein.name) filename = "%s.pka" % (protein.name)
file = open(filename, 'w') # TODO - this would be much better with a context manager
if verbose == True: file_ = open(filename, 'w')
if verbose:
info("Writing %s" % (filename)) info("Writing %s" % (filename))
# writing propka header # writing propka header
str = "%s\n" % ( getPropkaHeader() ) str_ = "%s\n" % get_propka_header()
str += "%s\n" % ( getReferencesHeader() ) str_ += "%s\n" % get_references_header()
str += "%s\n" % ( getWarningHeader() ) str_ += "%s\n" % get_warning_header()
# writing pKa determinant section # writing pKa determinant section
str += getDeterminantSection(protein,conformation, parameters) str_ += get_determinant_section(protein, conformation, parameters)
# writing pKa summary section # writing pKa summary section
str += getSummarySection(protein,conformation,parameters) str_ += get_summary_section(protein, conformation, parameters)
str += "%s\n" % ( getTheLine() ) str_ += "%s\n" % get_the_line()
# printing Folding Profile # printing Folding Profile
str += get_folding_profileSection(protein, conformation=conformation, reference=reference, window=[0., 14., 1.0]) str_ += get_folding_profile_section(protein, conformation=conformation,
reference=reference,
window=[0., 14., 1.0])
# printing Protein Charge Profile # printing Protein Charge Profile
str += get_charge_profileSection(protein, conformation=conformation) str_ += get_charge_profile_section(protein, conformation=conformation)
# now, writing the pka text to file # now, writing the pka text to file
file.write(str) file_.write(str_)
file_.close()
file.close()
def printTmProfile(protein, reference="neutral", window=[0., 14., 1.], Tm=[0.,0.], Tms=None, ref=None, verbose=False, options=None): def print_tm_profile(protein, reference="neutral", window=[0., 14., 1.],
__=[0., 0.], tms=None, ref=None, _=False,
options=None):
"""Print Tm profile.
I think Tm refers to the denaturation temperature.
Args:
protein: protein object
reference: reference state
window: pH window [min, max, step]
__: temperature range [min, max]
tms: TODO - figure this out
ref: TODO - figure this out (probably reference state?)
_: Boolean for verbosity
options: options object
""" """
prints Tm profile profile = protein.getTmProfile(reference=reference, grid=[0., 14., 0.1],
""" tms=tms, ref=ref, options=options)
profile = protein.getTmProfile(reference=reference, grid=[0., 14., 0.1], Tms=Tms, ref=ref, options=options) if profile is None:
if profile == None: str_ = "Could not determine Tm-profile\n"
str = "Could not determine Tm-profile\n"
else: else:
str = " suggested Tm-profile for %s\n" % (protein.name) str_ = " suggested Tm-profile for %s\n" % (protein.name)
for (pH, Tm) in profile: for (ph, tm_) in profile:
if pH >= window[0] and pH <= window[1] and (pH%window[2] < 0.01 or pH%window[2] > 0.99*window[2]): if ph >= window[0] and ph <= window[1] and (ph%window[2] < 0.01 \
str += "%6.2lf%10.2lf\n" % (pH, Tm) or ph%window[2] > 0.99*window[2]):
info(str) str_ += "%6.2lf%10.2lf\n" % (ph, tm_)
info(str_)
def printResult(protein, conformation, parameters): def print_result(protein, conformation, parameters):
"""Prints all resulting output from determinants and down.
Args:
protein: protein object
conformation: specific conformation
parameters: parameters
""" """
prints all resulting output from determinants and down print_pka_section(protein, conformation, parameters)
"""
printPKASection(protein, conformation, parameters)
def printPKASection(protein, conformation, parameters): def print_pka_section(protein, conformation, parameters):
""" """Prints out pKa section of results.
prints out the pka-section of the result
Args:
protein: protein object
conformation: specific conformation
parameters: parameters
""" """
# geting the determinants section # geting the determinants section
str = getDeterminantSection(protein, conformation, parameters) str_ = get_determinant_section(protein, conformation, parameters)
info(str) info(str_)
str_ = get_summary_section(protein, conformation, parameters)
str = getSummarySection(protein,conformation,parameters) info(str_)
info(str)
def getDeterminantSection(protein, conformation, parameters): def get_determinant_section(protein, conformation, parameters):
""" """Returns string with determinant section of results.
prints out the pka-section of the result
Args:
protein: protein object
conformation: specific conformation
parameters: parameters
Returns:
string
""" """
# getting the same order as in propka2.0 # getting the same order as in propka2.0
str = "%s\n" % ( getDeterminantsHeader() ) str_ = "%s\n" % get_determinants_header()
# printing determinants # printing determinants
for chain in protein.conformations[conformation].chains: for chain in protein.conformations[conformation].chains:
for residue_type in parameters.write_out_order: for residue_type in parameters.write_out_order:
groups = [g for g in protein.conformations[conformation].groups if g.atom.chain_id == chain] groups = [g for g in protein.conformations[conformation].groups \
if g.atom.chain_id == chain]
for group in groups: for group in groups:
if group.residue_type == residue_type: if group.residue_type == residue_type:
str += "%s" % ( group.get_determinant_string(parameters.remove_penalised_group) ) str_ += "%s" \
% group.get_determinant_string(parameters.remove_penalised_group)
# Add a warning in case of coupled residues # Add a warning in case of coupled residues
if protein.conformations[conformation].non_covalently_coupled_groups and not protein.options.display_coupled_residues: if protein.conformations[conformation].non_covalently_coupled_groups \
str += 'Coupled residues (marked *) were detected. Please rerun PropKa with the --display-coupled-residues \nor -d option for detailed information.\n' and not protein.options.display_coupled_residues:
str_ += 'Coupled residues (marked *) were detected.'
return str str_ += 'Please rerun PropKa with the --display-coupled-residues \n'
str_ += 'or -d option for detailed information.\n'
return str_
def getSummarySection(protein, conformation, parameters): def get_summary_section(protein, conformation, parameters):
"""Returns string with summary section of the results.
Args:
protein: protein object
conformation: specific conformation
parameters: parameters
Returns:
string
""" """
prints out the pka-section of the result str_ = "%s\n" % get_summary_header()
"""
str = "%s\n" % ( getSummaryHeader() )
# printing pKa summary # printing pKa summary
for residue_type in parameters.write_out_order: for residue_type in parameters.write_out_order:
for group in protein.conformations[conformation].groups: for group in protein.conformations[conformation].groups:
if group.residue_type == residue_type: if group.residue_type == residue_type:
str += "%s" % ( group.get_summary_string(parameters.remove_penalised_group) ) str_ += "%s" \
% group.get_summary_string(parameters.remove_penalised_group)
return str return str_
def get_folding_profileSection(protein, conformation='AVR', direction="folding", reference="neutral", window=[0., 14., 1.0], verbose=False, options=None): def get_folding_profile_section(protein, conformation='AVR',
direction="folding", reference="neutral",
window=[0., 14., 1.0], _=False,
__=None):
"""Returns string with the folding profile section of the results.
Args:
protein: protein object
conformation: specific conformation
direction: 'folding' or other
reference: reference state
window: pH window [min, max, step]
_: Boolean for verbose output
__: options object
Returns:
string
""" """
returns the protein-folding-profile section str_ = get_the_line()
""" str_ += "\n"
str = getTheLine() str_ += "Free energy of %9s (kcal/mol) as a function" % direction
str += "\n" str_ += " of pH (using %s reference)\n" % reference
str += "Free energy of %9s (kcal/mol) as a function of pH (using %s reference)\n" % (direction, reference) profile, [ph_opt, dg_opt], [dg_min, dg_max], [ph_min, ph_max] \
= protein.get_folding_profile(conformation=conformation,
profile, [pH_opt, dG_opt], [dG_min, dG_max], [pH_min, pH_max] = protein.get_folding_profile(conformation=conformation, reference=reference, grid=[0., 14., 0.1])
reference=reference, if profile is None:
grid=[0., 14., 0.1]) str_ += "Could not determine folding profile\n"
if profile == None:
str += "Could not determine folding profile\n"
else: else:
for (pH, dG) in profile: for (ph, dg) in profile:
if pH >= window[0] and pH <= window[1] and (pH%window[2] < 0.05 or pH%window[2] > 0.95): if ph >= window[0] and ph <= window[1]:
str += "%6.2lf%10.2lf\n" % (pH, dG) if ph%window[2] < 0.05 or ph%window[2] > 0.95:
str += "\n" str_ += "%6.2lf%10.2lf\n" % (ph, dg)
str_ += "\n"
if pH_opt == None or dG_opt == None: if ph_opt is None or dg_opt is None:
str += "Could not determine pH optimum\n" str_ += "Could not determine pH optimum\n"
else: else:
str += "The pH of optimum stability is %4.1lf for which the free energy is%6.1lf kcal/mol at 298K\n" % (pH_opt, dG_opt) str_ += "The pH of optimum stability is %4.1lf" % ph_opt
str_ += " for which the free energy is %6.1lf kcal/mol at 298K\n" % dg_opt
if dG_min == None or dG_max == None: if dg_min is None or dg_max is None:
str += "Could not determine pH values where the free energy is within 80 %s of minimum\n" % ("%") str_ += "Could not determine pH values where the free energy"
str_ += " is within 80 %s of minimum\n" % ("%")
else: else:
str += "The free energy is within 80 %s of maximum at pH %4.1lf to %4.1lf\n" % ("%", dG_min, dG_max) str_ += "The free energy is within 80 \% of maximum"
str_ += " at pH %4.1lf to %4.1lf\n" % (dg_min, dg_max)
if pH_min == None or pH_max == None: if ph_min is None or ph_max is None:
str += "Could not determine the pH-range where the free energy is negative\n\n" str_ += "Could not determine the pH-range where the free"
str_ += " energy is negative\n\n"
else: else:
str += "The free energy is negative in the range %4.1lf - %4.1lf\n\n" % (pH_min, pH_max) str_ += "The free energy is negative in the range"
str_ += " %4.1lf - %4.1lf\n\n" % (ph_min, ph_max)
return str_
return str def get_charge_profile_section(protein, conformation='AVR', _=None):
"""Returns string with the charge profile section of the results.
Args:
protein: protein object
def get_charge_profileSection(protein, conformation='AVR', options=None): conformation: specific conformation
_: options object
Returns:
string
""" """
returns the protein-folding-profile section str_ = "Protein charge of folded and unfolded state as a function of pH\n"
""" profile = protein.get_charge_profile(conformation=conformation,
str = "Protein charge of folded and unfolded state as a function of pH\n" grid=[0., 14., 1.])
if profile is None:
profile = protein.get_charge_profile(conformation=conformation,grid=[0., 14., 1.]) str_ += "Could not determine charge profile\n"
if profile == None:
str += "Could not determine charge profile\n"
else: else:
str += "%6s%10s%8s\n" % ("pH", "unfolded", "folded") str_ += "%6s%10s%8s\n" % ("pH", "unfolded", "folded")
for (pH, Q_mod, Q_pro) in profile: for (ph, q_mod, q_pro) in profile:
str += "%6.2lf%10.2lf%8.2lf\n" % (pH, Q_mod, Q_pro) str_ += "%6.2lf%10.2lf%8.2lf\n" % (ph, q_mod, q_pro)
pi_pro, pi_mod = protein.get_pi(conformation=conformation)
if pi_pro is None or pi_mod is None:
pI_pro, pI_mod = protein.get_pi(conformation=conformation) str_ += "Could not determine the pI\n\n"
if pI_pro == None or pI_mod == None:
str += "Could not determine the pI\n\n"
else: else:
str += "The pI is %5.2lf (folded) and %5.2lf (unfolded)\n" % (pI_pro, pI_mod) str_ += "The pI is %5.2lf (folded) and %5.2lf (unfolded)\n" % (pi_pro,
pi_mod)
return str_
return str def write_jackal_scap_file(mutation_data=None, filename="1xxx_scap.list",
_=None):
"""Write a scap file for, i.e., generating a mutated protein
TODO - figure out what this is
def writeJackalScapFile(mutationData=None, filename="1xxx_scap.list", options=None):
""" """
writing a scap file for, i.e., generating a mutated protein with open(filename, 'w') as file_:
for chain_id, _, res_num, code2 in mutation_data:
str_ = "%s, %d, %s\n" % (chain_id, res_num, code2)
file_.write(str_)
def write_scwrl_sequence_file(sequence, filename="x-ray.seq", _=None):
"""Write a scwrl sequence file for, e.g., generating a mutated protein
TODO - figure out what this is
""" """
file = open(filename, 'w') with open(filename, 'w') as file_:
for chain_id, code1, res_num, code2 in mutationData:
str = "%s, %d, %s\n" % (chain_id, res_num, code2)
file.write(str)
file.close()
def writeScwrlSequenceFile(sequence, filename="x-ray.seq", options=None):
"""
writing a scwrl sequence file for, e.g., generating a mutated protein
"""
file = open(filename, 'w')
start = 0 start = 0
while len(sequence[start:]) > 60: while len(sequence[start:]) > 60:
file.write( "%s\n" % (sequence[start:start+60]) ) file_.write("%s\n" % (sequence[start:start+60]))
start += 60 start += 60
file.write( "%s\n" % (sequence[start:]) ) file_.write("%s\n" % (sequence[start:]))
file.close()
def get_propka_header():
"""Create the header.
# --- various header text --- # Returns:
string
def getPropkaHeader():
""" """
Creates the header
"""
from datetime import date
today = date.today() today = date.today()
str_ = "propka3.1 %93s\n" % (today)
str_ += "-------------------------------------------------------------------------------------------------------\n"
str_ += "-- --\n"
str_ += "-- PROPKA: A PROTEIN PKA PREDICTOR --\n"
str_ += "-- --\n"
str_ += "-- VERSION 1.0, 04/25/2004, IOWA CITY --\n"
str_ += "-- BY HUI LI --\n"
str_ += "-- --\n"
str_ += "-- VERSION 2.0, 11/05/2007, IOWA CITY/COPENHAGEN --\n"
str_ += "-- BY DELPHINE C. BAS AND DAVID M. ROGERS --\n"
str_ += "-- --\n"
str_ += "-- VERSION 3.0, 01/06/2011, COPENHAGEN --\n"
str_ += "-- BY MATS H.M. OLSSON AND CHRESTEN R. SONDERGARD --\n"
str_ += "-- --\n"
str_ += "-- VERSION 3.1, 07/01/2011, COPENHAGEN --\n"
str_ += "-- BY CHRESTEN R. SONDERGARD AND MATS H.M. OLSSON --\n"
str_ += "-------------------------------------------------------------------------------------------------------\n"
str_ += "\n"
return str_
def get_references_header():
"""Create the 'references' part of output file.
str = "propka3.1 %93s\n" % (today) Returns:
str += "-------------------------------------------------------------------------------------------------------\n" string
str += "-- --\n"
str += "-- PROPKA: A PROTEIN PKA PREDICTOR --\n"
str += "-- --\n"
str += "-- VERSION 1.0, 04/25/2004, IOWA CITY --\n"
str += "-- BY HUI LI --\n"
str += "-- --\n"
str += "-- VERSION 2.0, 11/05/2007, IOWA CITY/COPENHAGEN --\n"
str += "-- BY DELPHINE C. BAS AND DAVID M. ROGERS --\n"
str += "-- --\n"
str += "-- VERSION 3.0, 01/06/2011, COPENHAGEN --\n"
str += "-- BY MATS H.M. OLSSON AND CHRESTEN R. SONDERGARD --\n"
str += "-- --\n"
str += "-- VERSION 3.1, 07/01/2011, COPENHAGEN --\n"
str += "-- BY CHRESTEN R. SONDERGARD AND MATS H.M. OLSSON --\n"
str += "-------------------------------------------------------------------------------------------------------\n"
str += "\n"
return str
def getReferencesHeader():
""" """
Returns the 'references' part in output file str_ = ""
str_ += "-------------------------------------------------------------------------------------------------------\n"
str_ += " References:\n"
str_ += "\n"
str_ += " Very Fast Empirical Prediction and Rationalization of Protein pKa Values\n"
str_ += " Hui Li, Andrew D. Robertson and Jan H. Jensen\n"
str_ += " PROTEINS: Structure, Function, and Bioinformatics 61:704-721 (2005)\n"
str_ += " \n"
str_ += " Very Fast Prediction and Rationalization of pKa Values for Protein-Ligand Complexes\n"
str_ += " Delphine C. Bas, David M. Rogers and Jan H. Jensen\n"
str_ += " PROTEINS: Structure, Function, and Bioinformatics 73:765-783 (2008)\n"
str_ += " \n"
str_ += " PROPKA3: Consistent Treatment of Internal and Surface Residues in Empirical pKa predictions\n"
str_ += " Mats H.M. Olsson, Chresten R. Sondergard, Michal Rostkowski, and Jan H. Jensen\n"
str_ += " Journal of Chemical Theory and Computation, 7(2):525-537 (2011)\n"
str_ += " \n"
str_ += " Improved Treatment of Ligands and Coupling Effects in Empirical Calculation\n"
str_ += " and Rationalization of pKa Values\n"
str_ += " Chresten R. Sondergaard, Mats H.M. Olsson, Michal Rostkowski, and Jan H. Jensen\n"
str_ += " Journal of Chemical Theory and Computation, (2011)\n"
str_ += " \n"
str_ += "-------------------------------------------------------------------------------------------------------\n"
return str_
def get_warning_header():
"""Create the 'warning' part of the output file.
TODO - this function is essentially a no-op.
Returns:
string
""" """
str_ = ""
str = "" return str_
str += "-------------------------------------------------------------------------------------------------------\n"
str += " References:\n"
str += "\n"
str += " Very Fast Empirical Prediction and Rationalization of Protein pKa Values\n"
str += " Hui Li, Andrew D. Robertson and Jan H. Jensen\n"
str += " PROTEINS: Structure, Function, and Bioinformatics 61:704-721 (2005)\n"
str += " \n"
str += " Very Fast Prediction and Rationalization of pKa Values for Protein-Ligand Complexes\n"
str += " Delphine C. Bas, David M. Rogers and Jan H. Jensen\n"
str += " PROTEINS: Structure, Function, and Bioinformatics 73:765-783 (2008)\n"
str += " \n"
str += " PROPKA3: Consistent Treatment of Internal and Surface Residues in Empirical pKa predictions\n"
str += " Mats H.M. Olsson, Chresten R. Sondergard, Michal Rostkowski, and Jan H. Jensen\n"
str += " Journal of Chemical Theory and Computation, 7(2):525-537 (2011)\n"
str += " \n"
str += " Improved Treatment of Ligands and Coupling Effects in Empirical Calculation\n"
str += " and Rationalization of pKa Values\n"
str += " Chresten R. Sondergaard, Mats H.M. Olsson, Michal Rostkowski, and Jan H. Jensen\n"
str += " Journal of Chemical Theory and Computation, (2011)\n"
str += " \n"
str += "-------------------------------------------------------------------------------------------------------\n"
return str
def getWarningHeader(): def get_determinants_header():
"""Create the Determinant header.
Returns:
string
""" """
Returns the 'warning' part in output file str_ = ""
str_ += "--------- ----- ------ --------------------- -------------- -------------- --------------\n"
str_ += " DESOLVATION EFFECTS SIDECHAIN BACKBONE COULOMBIC \n"
str_ += " RESIDUE pKa BURIED REGULAR RE HYDROGEN BOND HYDROGEN BOND INTERACTION \n"
str_ += "--------- ----- ------ --------- --------- -------------- -------------- --------------\n"
return str_
def get_summary_header():
"""Create the summary header.
Returns:
string
""" """
str_ = get_the_line()
str = "" str_ += "\n"
str_ += "SUMMARY OF THIS PREDICTION\n"
return str str_ += " Group pKa model-pKa ligand atom-type"
return str_
def getDeterminantsHeader(): def get_the_line():
"""Draw the line - Johnny Cash would have been proud - or actually Aerosmith!
NOTE - Johnny Cash walked the line.
Returns:
string
""" """
Creates the Determinant header str_ = ""
""" str_ += ("-" * 104)
str = "" return str_
str += "--------- ----- ------ --------------------- -------------- -------------- --------------\n"
str += " DESOLVATION EFFECTS SIDECHAIN BACKBONE COULOMBIC \n"
str += " RESIDUE pKa BURIED REGULAR RE HYDROGEN BOND HYDROGEN BOND INTERACTION \n"
str += "--------- ----- ------ --------- --------- -------------- -------------- --------------\n"
return str
def getSummaryHeader(): def make_interaction_map(name, list_, interaction):
"""
returns the summary header
"""
str = getTheLine()
str += "\n"
str += "SUMMARY OF THIS PREDICTION\n"
str += " Group pKa model-pKa ligand atom-type"
return str
def getTheLine():
"""
draw the line - Johnny Cash would have been proud - or actually Aerosmith!
"""
str = ""
for i in range(0, 104):
str += "-"
return str
# Interaction maps
def make_interaction_map(name, list, interaction):
"""Print out an interaction map named 'name' of the groups in 'list' """Print out an interaction map named 'name' of the groups in 'list'
based on the function 'interaction' """ based on the function 'interaction'
Args:
list_: list of groups
interaction: some sort of function
Returns:
string
"""
# return an empty string, if the list is empty # return an empty string, if the list is empty
if len(list)==0: if len(list_) == 0:
return '' return ''
# for long list, use condensed formatting # for long list, use condensed formatting
if len(list)>10: if len(list_) > 10:
res = 'Condensed form:\n' res = 'Condensed form:\n'
for i in range(len(list)): for i, group1 in enumerate(list_):
for j in range(i,len(list)): for group2 in list_[i:]:
if interaction(list[i],list[j]): if interaction(group1, group2):
res += 'Coupling: %9s - %9s\n'%(list[i].label,list[j].label) res += 'Coupling: %9s - %9s\n' % (group1.label,
group2.label)
return res return res
# Name and map header # Name and map header
res = '%s\n%12s' % (name, '') res = '%s\n%12s' % (name, '')
for g in list: for group in list_:
res += '%9s | '%g.label res += '%9s | ' % group.label
# do the map # do the map
for g1 in list: for group1 in list_:
res += '\n%-12s'%(g1.label) res += '\n%-12s' % (group1.label)
for g2 in list: for group2 in list_:
tag = '' tag = ''
if interaction(g1, g2): if interaction(group1, group2):
tag = ' X ' tag = ' X '
res += '%10s| '%tag res += '%10s| '%tag
return res return res

View File

@@ -433,9 +433,9 @@ if __name__ == '__main__':
my_protein = protein.Protein(pdblist,'test.pdb') my_protein = protein.Protein(pdblist,'test.pdb')
p.remove_all_hydrogen_atoms_from_protein(my_protein) p.remove_all_hydrogen_atoms_from_protein(my_protein)
my_protein.writePDB('before_protonation.pdb') my_protein.write_pdb('before_protonation.pdb')
p.protonate_protein(my_protein) p.protonate_protein(my_protein)
## write out protonated file ## write out protonated file
my_protein.writePDB('protonated.pdb') my_protein.write_pdb('protonated.pdb')