forked from Pymol-Scripts/Pymol-script-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_pdb_with_anisou.py
51 lines (33 loc) · 1.16 KB
/
save_pdb_with_anisou.py
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
'''
http://pymolwiki.org/index.php/Save_pdb_with_anisou
(c) 2012 Thomas Holder, MPI for Developmental Biology
License: BSD-2-Clause
'''
from __future__ import print_function
from pymol import cmd, CmdException
def save_pdb_with_anisou(filename, selection='(all)', state=1, quiet=1):
'''
DESCRIPTION
Save in PDB format including ANISOU records.
SEE ALSO
save
'''
state, quiet = int(state), int(quiet)
pdbstr = cmd.get_pdbstr(selection, state)
atom_it = iter(cmd.get_model(selection, state).atom)
def mergeaniso():
for line in pdbstr.splitlines(True):
yield line
if line[:6] in ['ATOM ', 'HETATM']:
u_str = ''.join('%7.0f' % (u * 1e4) for u in atom_it.next().u_aniso)
yield 'ANISOU' + line[6:28] + u_str + line[70:]
pdbstr = ''.join(mergeaniso())
filename = cmd.exp_path(filename)
f = open(filename, 'w')
f.write(pdbstr)
f.close()
if not quiet:
print(' Save with ANISOU: wrote "%s"' % (filename))
cmd.extend('save_pdb_with_anisou', save_pdb_with_anisou)
cmd.auto_arg[1]['save_pdb_with_anisou'] = cmd.auto_arg[1]['save']
# vi:expandtab:smarttab