/usr/lib/python2.7/dist-packages/csb/apps/bfite.py is in python-csb 1.2.3+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | """
Python application for robust structure superposition of an ensemble of structures.
bfite models non-rigid displacements in protein ensembles with outlier-tolerant
probability distributions.
"""
import numpy
import csb.apps
import csb.bio.structure
from csb.bio.io.wwpdb import LegacyStructureParser
from csb.bio.utils import average_structure, fit, wfit
from csb.statistics.scalemixture import ScaleMixture, GammaPrior
class ExitCodes(csb.apps.ExitCodes):
IO_ERROR = 2
class AppRunner(csb.apps.AppRunner):
@property
def target(self):
return BFitApp
def command_line(self):
cmd = csb.apps.ArgHandler(self.program, __doc__)
# Input structures
cmd.add_positional_argument('pdb', str,
'full path to the ensemble')
# Optional arguments
cmd.add_scalar_option('chain', 'c', str,
'Chain',
default='A')
cmd.add_scalar_option('scalemixture', 's', str,
'Scale mixture distribution',
default='student',
choices=['student', 'k'])
cmd.add_scalar_option('alignment', 'a', str,
'Alignment in fasta format defining equivalent positions\n'
+ 'Assumes that chain1 is the first sequence of '
+ 'the alignment and chain2 the second sequence')
cmd.add_scalar_option('outfile', 'o', str,
'file to which the rotated second ' +
'structure will be written',
default='bfit.pdb')
cmd.add_scalar_option('niter', 'n', int,
'Number of optimization steps',
default=200)
return cmd
class BFitApp(csb.apps.Application):
"""
Python application for robust structure superposition of two protein structures
"""
def main(self):
try:
parser = LegacyStructureParser(self.args.pdb)
models = parser.models()
except IOError as e:
self.exit('PDB file parsing failed\n' + str(e.value), ExitCodes.IO_ERROR)
if len(models) < 2:
self.exit('PDB file contains only one model', ExitCodes.USAGE_ERROR)
ensemble = parser.parse_models(models)
X = numpy.array([model[self.args.chain].get_coordinates(['CA'], True) for model in ensemble])
x_mu = average_structure(X)
#n = X.shape[1]
m = X.shape[0]
R = numpy.zeros((m, 3, 3))
t = numpy.ones((m, 3))
prior = GammaPrior()
mixture = ScaleMixture(scales=X.shape[1],
prior=prior, d=3)
for i in range(m):
R[i, :, :], t[i, :] = fit(x_mu, X[i])
# gibbs sampling cycle
for j in range(self.args.niter):
# apply rotation
data = numpy.array([numpy.sum((x_mu - numpy.dot(X[i], numpy.transpose(R[i])) - t[i]) ** 2, -1) ** 0.5
for i in range(m)]).T
# sample scales
mixture.estimate(data)
# sample rotations
for i in range(m):
R[i, :, :], t[i, :] = wfit(x_mu, X[i], mixture.scales)
out_ensemble = csb.bio.structure.Ensemble()
for i, model in enumerate(ensemble):
model.transform(R[i], t[i])
out_ensemble.models.append(model)
out_ensemble.to_pdb(self.args.outfile)
def main():
AppRunner().run()
if __name__ == '__main__':
main()
|