~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to tools/moltemplate/examples/CG_biomolecules/metaphase_chromatin_Naumova+Imakaev2013/moltemplate_files/interpolate_coords.py

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
 
4
 
err_msg = """
5
 
Usage:
6
 
 
7
 
   interpolate_coords.py Ndesired [scale] < coords_orig.raw > coords.raw
8
 
 
9
 
Example:
10
 
 
11
 
   interpolate_coords.py 30118 3.0 < coords_orig.raw > coords.raw
12
 
 
13
 
   # (Note: 30117 ~= 128000/4.25, but using 30118 makes interpolation cleaner.
14
 
   #        See the supplemental section of Naumova et al Science 2013, p 18.)
15
 
 
16
 
"""
17
 
 
18
 
 
19
 
import sys
20
 
from math import *
21
 
 
22
 
# Parse the argument list:
23
 
if len(sys.argv) <= 1:
24
 
    sys.stderr.write("Error:\n\nTypical Usage:\n\n"+err_msg+"\n")
25
 
    exit(1)
26
 
 
27
 
n_new = int(sys.argv[1])
28
 
 
29
 
if len(sys.argv) > 2:
30
 
    scale = float(sys.argv[2])
31
 
else:
32
 
    scale = 1.0
33
 
 
34
 
coords_orig = []
35
 
 
36
 
lines = sys.stdin.readlines()
37
 
 
38
 
for line in lines:
39
 
    tokens = line.split()
40
 
    if (len(tokens) > 0):
41
 
        coords_orig.append(map(float, tokens))
42
 
        g_dim = len(tokens)
43
 
 
44
 
n_orig = len(coords_orig)
45
 
 
46
 
if n_orig < 2:
47
 
    sys.stderr.write("Error:\n\nInput file contains less than two lines of coordinates\n")
48
 
    exit(1)
49
 
 
50
 
if n_new < 2:
51
 
    sys.stderr.write("Error:\n\nOutput file will contain less than two lines of coordinates\n")
52
 
    exit(1)
53
 
 
54
 
coords_new = [[0.0 for d in range(0, g_dim)] for i in range(0, n_new)]
55
 
 
56
 
for i_new in range(0, n_new):
57
 
    I_orig = (i_new) * (float(n_orig-1) / float(n_new-1))
58
 
    i_orig = int(floor(I_orig))
59
 
    i_remainder = I_orig - i_orig
60
 
 
61
 
    if (i_new < n_new-1):
62
 
        for d in range(0, g_dim):
63
 
            coords_new[i_new][d] = scale*(coords_orig[i_orig][d]
64
 
                                          +
65
 
                                          i_remainder*(coords_orig[i_orig+1][d]-
66
 
                                                       coords_orig[i_orig][d]))
67
 
    else:
68
 
        for d in range(0, g_dim):
69
 
            coords_new[i_new][d] = scale*coords_orig[n_orig-1][d]
70
 
 
71
 
    # print the coordates
72
 
    for d in range(0, g_dim-1):
73
 
        sys.stdout.write(str(coords_new[i_new][d]) + ' ')
74
 
    sys.stdout.write(str(coords_new[i_new][g_dim-1]) + "\n")