<div dir="ltr">Hi Nicholas,<div><br></div><div>First, the most basic way to calculate torsion (dihedral) angle for 4 given atoms is:</div><div>from scitbx.math import dihedral_angle<br></div><div>angle = dihedral_angle(sites=[(1,0,0), (0,0,0), (0,1,0), (1,1,0)], deg=True)<br></div><div>where 'sites' contain atom coordinates.</div><div><br></div><div>Second, here is more high-level way to get phi-psi angles:<br></div><div><div> from mmtbx.conformation_dependent_library import generate_protein_threes</div><div> pdb_h = iotbx.pdb.hierarchy.input(file_name=args[0]).hierarchy</div><div> sites_cart = pdb_h.atoms().extract_xyz()</div><div> # Note that this is a generator<br></div><div> for three in generate_protein_threes(</div><div> hierarchy=pdb_h,</div><div> geometry=None):</div><div> proxies = three.get_dummy_dihedral_proxies()</div><div> for p in proxies:</div><div> print "angle=", dihedral_angle(<br></div><div> sites=[sites_cart[x] for x in p.i_seqs], </div><div> deg=True)</div><div><br></div><div>Third, to get all proxies, use this function with hierarchy:</div><div><div> from mmtbx.geometry_restraints.torsion_restraints.utils import \</div><div> get_complete_dihedral_proxies</div></div></div><div><div> dih_proxies = get_complete_dihedral_proxies(</div><div> pdb_hierarchy=pdb_h)</div></div><div><br></div><div>Hope this helps, full script is below and attached (run with pdb file as the only argument).</div><div><br></div><div>Best regards,</div><div>Oleg Sobolev.</div><div><br></div><div><div>import sys</div><div>from scitbx.math import dihedral_angle</div><div>import iotbx.pdb</div><div>import os.path</div><div><br></div><div>def basics():<br></div><div> print "Basics:"</div><div> angle = dihedral_angle(sites=[(1,0,0), (0,0,0), (0,1,0), (1,1,0)], deg=True)</div><div> print "Angle:", angle</div><div> angle = dihedral_angle(sites=[(2,1,1), (0,0,0), (0,1,0), (1,1,0)], deg=True)</div><div> print "Angle in degrees:", angle</div><div> angle = dihedral_angle(sites=[(2,1,1), (0,0,0), (0,1,0), (1,1,0)], deg=False)</div><div> print "Angle in radians:", angle</div><div> print "="*50</div><div><br></div><div>def advanced(args):</div><div> print "Advanced phi-psi:"</div><div> if len(args) != 1 or not os.path.isfile(args[0]):</div><div> print "Bad argument"</div><div> return</div><div><br></div><div> # phi-psi angles</div><div> from mmtbx.conformation_dependent_library import generate_protein_threes</div><div> pdb_h = iotbx.pdb.hierarchy.input(file_name=args[0]).hierarchy</div><div> sites_cart = pdb_h.atoms().extract_xyz()</div><div> n_proxies = 0</div><div> # Note that this is a generator</div><div> for three in generate_protein_threes(</div><div> hierarchy=pdb_h,</div><div> geometry=None):</div><div> proxies = three.get_dummy_dihedral_proxies()</div><div> for p in proxies:</div><div> for i_seq in p.i_seqs:</div><div> print pdb_h.atoms()[i_seq].id_str(),</div><div> print "angle=", dihedral_angle(</div><div> sites=[sites_cart[x] for x in p.i_seqs], </div><div> deg=True)</div><div> n_proxies += 1</div><div> print "Total angles:", n_proxies</div><div><br></div><div><br></div><div>def all_dihedral_proxies(args):</div><div> print "Advanced all:"</div><div> if len(args) != 1 or not os.path.isfile(args[0]):</div><div> print "Bad argument"</div><div> return</div><div> # all angles:</div><div> from mmtbx.geometry_restraints.torsion_restraints.utils import \</div><div> get_complete_dihedral_proxies</div><div><br></div><div> pdb_h = iotbx.pdb.hierarchy.input(file_name=args[0]).hierarchy</div><div> sites_cart = pdb_h.atoms().extract_xyz()</div><div> dih_proxies = get_complete_dihedral_proxies(</div><div> pdb_hierarchy=pdb_h)</div><div> for p in dih_proxies:</div><div> for i_seq in p.i_seqs:</div><div> print pdb_h.atoms()[i_seq].id_str(),</div><div> print "angle=", dihedral_angle(</div><div> sites=[sites_cart[x] for x in p.i_seqs], </div><div> deg=True)</div><div> print "Total angles:", dih_proxies.size()</div><div><br></div><div>def run(args):</div><div> basics()</div><div> advanced(args)</div><div> all_dihedral_proxies(args)</div><div><br></div><div>if (__name__ == "__main__"):</div><div> run(sys.argv[1:])</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 20, 2015 at 3:30 PM, Nicholas Pearce <span dir="ltr"><<a href="mailto:nicholas.pearce@stx.ox.ac.uk" target="_blank">nicholas.pearce@stx.ox.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Everyone,<br>
<br>
Phenomenally stupid question, but is there an easy way to calculate phi-psi angles for a protein using cctbx? And, following on from that, Chi-1, Chi-2 etc angles?<br>
<br>
I’ve had a poke around, but couldn’t find any obvious (at least to me) way that worked…<br>
<br>
I presume this must be implemented rigorously somewhere, and I didn’t want to waste time reimplementing the wheel.<br>
<br>
Thanks,<br>
Nick<br>
_______________________________________________<br>
cctbxbb mailing list<br>
<a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a><br>
<a href="http://phenix-online.org/mailman/listinfo/cctbxbb" rel="noreferrer" target="_blank">http://phenix-online.org/mailman/listinfo/cctbxbb</a><br>
</blockquote></div><br></div>