Pymol(1.8.6)作图技巧之创建质心

举报
DrugAI 发表于 2021/07/15 05:48:00 2021/07/15
【摘要】 一、首先,访问pymolwikiCenter of Mass,下载center_of_mass.py脚本; 或者把下面文件保存为center_of_mass.py文件。 See more here: http://www.pymolwiki.org/index.php/center_of_mass DESCRIPTION Places a pseudoa...


一、首先,访问pymolwikiCenter of Mass,下载center_of_mass.py脚本;

或者把下面文件保存为center_of_mass.py文件。


  
  1. See more here: http://www.pymolwiki.org/index.php/center_of_mass
  2. DESCRIPTION
  3. Places a pseudoatom at the center of mass
  4. Author: Sean Law
  5. Michigan State University
  6. slaw (at) msu . edu
  7. SEE ALSO
  8. pseudoatom, get_com
  9. '''
  10. from __future__ import print_function
  11. from pymol import cmd
  12. def com(selection, state=None, mass=None, object=None, quiet=1, **kwargs):
  13. quiet = int(quiet)
  14. if (object == None):
  15. try:
  16. object = cmd.get_legal_name(selection)
  17. object = cmd.get_unused_name(object + "_COM", 0)
  18. except AttributeError:
  19. object = 'COM'
  20. cmd.delete(object)
  21. if (state != None):
  22. x, y, z = get_com(selection, mass=mass, quiet=quiet)
  23. if not quiet:
  24. print("%f %f %f" % (x, y, z))
  25. cmd.pseudoatom(object, pos=[x, y, z], **kwargs)
  26. cmd.show("spheres", object)
  27. else:
  28. for i in range(cmd.count_states()):
  29. x, y, z = get_com(selection, mass=mass, state=i + 1, quiet=quiet)
  30. if not quiet:
  31. print("State %d:%f %f %f" % (i + 1, x, y, z))
  32. cmd.pseudoatom(object, pos=[x, y, z], state=i + 1, **kwargs)
  33. cmd.show("spheres", 'last ' + object)
  34. cmd.extend("com", com)
  35. def get_com(selection, state=1, mass=None, quiet=1):
  36. """
  37. DESCRIPTION
  38. Calculates the center of mass
  39. Author: Sean Law
  40. Michigan State University
  41. slaw (at) msu . edu
  42. """
  43. quiet = int(quiet)
  44. totmass = 0.0
  45. if mass != None and not quiet:
  46. print("Calculating mass-weighted COM")
  47. state = int(state)
  48. model = cmd.get_model(selection, state)
  49. x, y, z = 0, 0, 0
  50. for a in model.atom:
  51. if (mass != None):
  52. m = a.get_mass()
  53. x += a.coord[0] * m
  54. y += a.coord[1] * m
  55. z += a.coord[2] * m
  56. totmass += m
  57. else:
  58. x += a.coord[0]
  59. y += a.coord[1]
  60. z += a.coord[2]
  61. if (mass != None):
  62. return x / totmass, y / totmass, z / totmass
  63. else:
  64. return x / len(model.atom), y / len(model.atom), z / len(model.atom)
  65. cmd.extend("get_com", get_com)
  66. # vi:expandtab:sw=3

二、将center_of_mass.py脚本放在pymol安装文件夹下的Lib文件夹。



三、创建质心操作

导入center of mass

import center_of_mass

创建质心球



修改质心球大小

set sphere_scale,0.4


创建质心的其他相关操作




文章来源: drugai.blog.csdn.net,作者:DrugAI,版权归原作者所有,如需转载,请联系作者。

原文链接:drugai.blog.csdn.net/article/details/77345827

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。