rg.py

Calculates the radius of gyration from given pdb file coordinates
USAGE:
python rg.py file.pdb

Keywords:

Categories:

  • core/calc/structural/calculate_Rg_square

Program source:

 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
import sys, math

sys.path.append('../../../../../bin/')
from pybioshell.core.data.io import find_pdb
from pybioshell.core.data.basic import Vec3
from pybioshell.std import vector_core_data_basic_Vec3

from pybioshell.core.calc.structural import *
from pybioshell.utils import LogManager
LogManager.INFO()



if len(sys.argv) < 2 :
    print("""

    Calculates the radius of gyration from given pdb file coordinates

USAGE:
    python rg.py file.pdb

    CATEGORIES: core/calc/structural/calculate_Rg_square
    KEYWORDS:   PDB input; radius of gyration

  """)
    sys.exit()

for pdb_fname in sys.argv[1:] :
    pdb=find_pdb(pdb_fname, "./")
    n_atoms = pdb.count_atoms(0)
  
    structure = pdb.create_structure(0)
    models=[]

    for i_model in range(0, pdb.count_models()) :
      xyz=vector_core_data_basic_Vec3()
      for i in range(n_atoms) : xyz.append( Vec3() )
      models.append(xyz)

    for i_model in range(0, pdb.count_models()) :
      pdb.fill_structure(i_model, models[i_model])
      try:
        print("Rg for %s, model # %5d : %7.3f" % (pdb_fname.split("/")[-1].split(".")[0],i_model,
    	math.sqrt(calculate_Rg_square(models[i_model][0], models[i_model][n_atoms-1]))))
      except:
        sys.stderr.write(str(sys.exc_info()[0])+" "+str(sys.exc_info()[1]))



../_images/file_icon.png