-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcombine_curve.py
55 lines (49 loc) · 1.75 KB
/
combine_curve.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
52
53
54
55
import numpy as np
import optparse
import os
def read_file_safe(filename, dtype="float64"):
"""
Simple check if file exists
:param filename:
:return:
"""
try:
results = np.genfromtxt(filename, dtype=dtype)
except IOError as err:
print(os.strerror(err.errno))
return results
def combine_curve(simulated, weights, scale):
"""
:param simulated:
:param weights:
:param scale:
:return:
"""
combuined = scale*np.dot(weights, np.transpose(simulated))
return combuined
if __name__ == "__main__":
doc = """
Python interface to Variational Bayesian algorithm
Usage: python runVBW.py --help
"""
print(doc)
usage = "usage: %prog [options] args"
option_parser_class = optparse.OptionParser
parser = option_parser_class( usage = usage, version='0.1' )
parser.add_option("-w", "--weights", dest="weights", default=None,
help="Posterior weights [OBLIGATORY]")
parser.add_option("-s", "--simulated", dest="simulated_file",
help="Simulated SAXS curves [OBLIGATORY]")
parser.add_option("-e", "--experimenttal", dest="experimental_file",
help="Simulated SAXS curves [OBLIGATORY]")
parser.add_option("-k", "--scale", dest="scale", default=1,
type='float',
help="scaling factor")
options, args = parser.parse_args()
scale = options.scale
weights = read_file_safe(options.weights)
simulated = read_file_safe(options.simulated_file)
experimental = read_file_safe(options.experimental_file)
combined = combine_curve(simulated, weights, scale)
q_column = experimental[:,0]
np.savetxt("combinedCurveqIq.txt", np.transpose((q_column, combined)))