本文整理汇总了Python中ZIBMolPy.pool.Pool.alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.alpha方法的具体用法?Python Pool.alpha怎么用?Python Pool.alpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZIBMolPy.pool.Pool
的用法示例。
在下文中一共展示了Pool.alpha方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ZIBMolPy.pool import Pool [as 别名]
# 或者: from ZIBMolPy.pool.Pool import alpha [as 别名]
def main():
options = options_desc.parse_args(sys.argv)[0]
#TODO put somehow into Options, e.g. min_value=1 or required=True
if(not options.doomed_nodes):
sys.exit("Option --doomed_nodes is required.")
pool = Pool()
old_pool_size = len(pool)
old_alpha = pool.alpha
doomed_nodes = NodeList()
#TODO: maybe this code should go into ZIBMolPy.ui
for name in options.doomed_nodes.split(","):
found = [n for n in pool if n.name == name]
if(len(found) != 1):
sys.exit("Coult not find node '%s'"%(name))
doomed_nodes.append(found[0])
for n in doomed_nodes:
if(n == pool.root):
sys.exit("Node %s is the root. Removal not allowed."%(n.name))
#if(len(n.children) > 0):
# sys.exit("Node %s has children. Removal not allowed."%(n.name)) #TODO why should we forbid this?
if not(userinput("The selected node(s) will be removed permanently. Continue?", "bool")):
sys.exit("Quit by user.")
assert(len(doomed_nodes) == len(doomed_nodes.multilock()))
for n in doomed_nodes:
print("Removing directory: "+n.dir)
shutil.rmtree(n.dir)
pool.reload_nodes()
#TODO: this code-block also exists in zgf_create_node
if(len(pool.where("isa_partition")) < 2):
pool.alpha = None
elif(options.methodalphas == "theta"):
pool.alpha = zgf_create_nodes.calc_alpha_theta(pool)
elif(options.methodalphas == "user"):
pool.alpha = userinput("Please enter a value for alpha", "float")
else:
raise(Exception("Method unkown: "+options.methodalphas))
pool.history.append({'removed_nodes': [(n.name, n.state) for n in doomed_nodes], 'size':old_pool_size, 'alpha':old_alpha, 'timestamp':datetime.now()})
pool.save()
#TODO: deal with analysis dir and dependencies
zgf_cleanup.main()
示例2: main
# 需要导入模块: from ZIBMolPy.pool import Pool [as 别名]
# 或者: from ZIBMolPy.pool.Pool import alpha [as 别名]
#.........这里部分代码省略.........
else:
mdp_options["energygrps"] = "MOI"
mdp_options_dirty = True
a, b = mdp_options.has_key("nstxout"), mdp_options.has_key("nstenergy")
if a and not b:
mdp_options["nstenergy"] = mdp_options["nstxout"]
mdp_options_dirty = True
elif b and not a:
mdp_options["nstxout"] = mdp_options["nstenergy"]
mdp_options_dirty = True
elif b and a:
assert mdp_options["nstxout"] == mdp_options["nstenergy"], "nstxout should equal nstenergy"
if int(mdp_options["nsteps"]) > 1e6:
msg = "Number of MD-steps?"
mdp_options["nsteps"] = str(userinput(msg, "int", default=int(mdp_options["nsteps"])))
# create a fixed mdp-file
if mdp_options_dirty:
print("Creating copy of mdp-file and adding missing options.")
out_fn = options.grompp.rsplit(".", 1)[0] + "_fixed.mdp"
f = open(out_fn, "w") # append
f.write("; Generated by zgf_create_pool\n")
for i in mdp_options.items():
f.write("%s = %s\n" % i)
f.write("; EOF\n")
f.close()
options.grompp = out_fn
# check if subsampling is reasonable
if os.path.getsize(options.presampling) > 100e6: # 100MB
print("Presampling trajectory is large")
trr = TrrFile(options.presampling)
dt = trr.first_frame.next().t - trr.first_frame.t
trr.close()
print("Presampling timestep is %.2f ps" % dt)
if dt < 10: # picoseconds
# TODO: maybe calculate subsampling factor individually, or ask?
msg = "Subsample presampling trajectory by a tenth?"
if userinput(msg, "bool"):
out_fn = options.presampling.rsplit(".", 1)[0] + "_tenth.trr"
cmd = ["trjconv", "-f", options.presampling, "-o", out_fn, "-skip", "10"]
check_call(cmd)
options.presampling = out_fn
# balance linears
if options.balance_linears:
print("Balance Linears")
old_converter = Converter(options.internals)
print("Loading presampling....")
frames = old_converter.read_trajectory(options.presampling)
new_coord_list = []
for c in old_converter:
if not isinstance(c, LinearCoordinate):
new_coord_list.append(c)
continue # we do not work on other Coordinate-Types
# TODO: is this a good way to determine new_weight and new_offset???
new_weight = c.weight / sqrt(2 * frames.var().getcoord(c))
new_offset = c.offset + frames.mean().getcoord(c)
new_coord = LinearCoordinate(*c.atoms, label=c.label, weight=new_weight, offset=new_offset)
new_coord_list.append(new_coord)
new_converter = Converter(coord_list=new_coord_list)
assert old_converter.filename.endswith(".int")
options.internals = old_converter.filename[:-4] + "_balanced.int"
print("Writing balanced Converter to: " + options.internals)
f = open(options.internals, "w")
f.write(new_converter.serialize())
f.close()
assert len(Converter(options.internals)) == len(new_coord_list) # try parsing
# Finally: Create root-node and pool
pool = Pool()
if len(pool) != 0:
print("ERROR: A pool already exists here.")
sys.exit(1)
pool.int_fn = options.internals
pool.mdp_fn = options.grompp
pool.top_fn = options.topology
pool.ndx_fn = options.index
pool.temperature = options.temperature
pool.gr_threshold = options.gr_threshold
pool.gr_chains = options.gr_chains
pool.alpha = None
pool.save() # save pool for the first time...
# ... then we can save the first node...
node0 = Node()
node0.state = "refined"
node0.save() # also creates the node directory ... needed for symlink
os.symlink(os.path.relpath(options.presampling, node0.dir), node0.trr_fn)
os.symlink(os.path.relpath(options.molecule, node0.dir), node0.pdb_fn)
pool.root_name = node0.name
pool.save() # ... now we have to save the pool again.
if not path.exists("analysis"):
os.mkdir("analysis")
示例3: main
# 需要导入模块: from ZIBMolPy.pool import Pool [as 别名]
# 或者: from ZIBMolPy.pool.Pool import alpha [as 别名]
#.........这里部分代码省略.........
sys.exit("Quit by user.")
a, b = mdp_options.has_key("nstxout"), mdp_options.has_key("nstenergy")
if(a and not b):
mdp_options["nstenergy"] = mdp_options["nstxout"]
mdp_options_dirty = True
elif(b and not a):
mdp_options["nstxout"] = mdp_options["nstenergy"]
mdp_options_dirty = True
elif(b and a):
assert(mdp_options["nstxout"] == mdp_options["nstenergy"]), "nstxout should equal nstenergy"
if(int(mdp_options["nsteps"]) > 1e6):
msg = "Number of MD-steps?"
mdp_options["nsteps"] = str( userinput(msg, "int", default=int(mdp_options["nsteps"])) )
# create a fixed mdp-file
if(mdp_options_dirty):
print("Creating copy of mdp-file and adding missing options.")
out_fn = options.grompp.rsplit(".", 1)[0] + "_fixed.mdp"
f = open(out_fn, "w") # append
f.write("; Generated by zgf_create_pool\n")
for i in sorted(mdp_options.items()):
f.write("%s = %s\n"%i)
f.write("; EOF\n")
f.close()
options.grompp = out_fn
# check if subsampling is reasonable
if(os.path.getsize(options.presampling) > 100e6): # 100MB
print("Presampling trajectory is large")
trr = TrrFile(options.presampling)
dt = trr.first_frame.next().t - trr.first_frame.t
trr.close()
print("Presampling timestep is %.2f ps"%dt)
if(dt < 10): # picoseconds
#TODO: maybe calculate subsampling factor individually, or ask?
msg = "Subsample presampling trajectory by a tenth?"
if(userinput(msg, "bool")):
out_fn = options.presampling.rsplit(".", 1)[0] + "_tenth.trr"
cmd = ["trjconv", "-f", options.presampling, "-o", out_fn, "-skip", "10"]
check_call(cmd)
options.presampling = out_fn
# balance linears
if(options.balance_linears):
print("Balance Linears")
old_converter = Converter(options.internals)
print("Loading presampling....")
frames = old_converter.read_trajectory(options.presampling)
new_coord_list = []
for c in old_converter:
if(not isinstance(c, LinearCoordinate)):
new_coord_list.append(c)
continue # we do not work on other Coordinate-Types
#TODO: is this a good way to determine new_weight and new_offset???
new_weight = c.weight / sqrt(2*frames.var().getcoord(c))
new_offset = c.offset + frames.mean().getcoord(c)
new_coord = LinearCoordinate(*c.atoms, label=c.label, weight=new_weight, offset=new_offset)
new_coord_list.append(new_coord)
new_converter = Converter(coord_list=new_coord_list)
assert(old_converter.filename.endswith(".int"))
options.internals = old_converter.filename[:-4] + "_balanced.int"
print("Writing balanced Converter to: "+options.internals)
f = open(options.internals, "w")
f.write(new_converter.serialize())
f.close()
assert(len(Converter(options.internals)) == len(new_coord_list)) #try parsing
# Finally: Create root-node and pool
pool = Pool()
if(len(pool) != 0):
print("ERROR: A pool already exists here.")
sys.exit(1)
pool.int_fn = options.internals
pool.mdp_fn = options.grompp
pool.top_fn = options.topology
pool.ndx_fn = options.index
pool.temperature = int(temperature)
pool.gr_threshold = options.gr_threshold
pool.gr_chains = options.gr_chains
pool.alpha = None
pool.save() # save pool for the first time...
# ... then we can save the first node...
node0 = Node()
node0.state = "refined"
node0.save() # also creates the node directory ... needed for symlink
os.symlink(os.path.relpath(options.presampling, node0.dir), node0.trr_fn)
os.symlink(os.path.relpath(options.molecule, node0.dir), node0.pdb_fn)
pool.root_name = node0.name
pool.save() #... now we have to save the pool again.
if(not path.exists("analysis")):
os.mkdir("analysis")
示例4: main
# 需要导入模块: from ZIBMolPy.pool import Pool [as 别名]
# 或者: from ZIBMolPy.pool.Pool import alpha [as 别名]
def main(argv=None):
if(argv==None):
argv = sys.argv
options = options_desc.parse_args(argv)[0]
print("Options:\n%s\n"%pformat(eval(str(options))))
if(options.random_seed):
# using numpy-random because python-random differs beetween 32 and 64 bit
np.random.seed(hash(options.random_seed))
pool = Pool()
old_pool_size = len(pool)
print "pool", pool
if(options.parent_node == "root"):
parent = pool.root
else:
found = [n for n in pool if n.name == options.parent_node]
assert(len(found) == 1)
parent = found[0]
print "### Generate nodes: %s ###" % options.methodnodes
if(options.methodnodes == "kmeans"):
chosen_idx = mknodes_kmeans(parent, options.numnodes)
elif(options.methodnodes == "equidist"):
chosen_idx = mknodes_equidist(parent, options.numnodes)
elif(options.methodnodes == "maxdist"):
chosen_idx = mknodes_maxdist(parent, options.numnodes)
elif(options.methodnodes == "all"):
chosen_idx = mknodes_all(parent)
else:
raise(Exception("Method unknown: "+options.methodnodes))
chosen_idx.sort() # makes preview-trajectory easier to understand
if(options.write_preview):
write_node_preview(pool, parent, chosen_idx)
for i in chosen_idx:
n = Node()
n.parent_frame_num = i
n.parent = parent
n.state = "creating-a-partition" # will be set to "created" at end of script
n.extensions_counter = 0
n.extensions_max = options.ext_max
n.extensions_length = options.ext_length
n.sampling_length = options.sampling_length
n.internals = parent.trajectory.getframe(i)
pool.append(n)
print "\n### Obtain alpha: %s ###" % options.methodalphas
old_alpha = pool.alpha
if(options.methodalphas == "theta"):
pool.alpha = calc_alpha_theta(pool)
elif(options.methodalphas == "user"):
pool.alpha = userinput("Please enter a value for alpha", "float")
else:
raise(Exception("Method unknown: "+options.methodalphas))
pool.history.append({'refined_node': (parent.name, parent.state), 'size':old_pool_size, 'alpha':old_alpha, 'timestamp':datetime.now()})
pool.save() # alpha might have changed
print "\n### Obtain phi fit: %s ###" % options.methodphifit
if(options.methodphifit == "harmonic"):
do_phifit_harmonic(pool)
elif(options.methodphifit == "switch"):
do_phifit_switch(pool)
elif(options.methodphifit == "leastsq"):
do_phifit_leastsq(pool)
else:
raise(Exception("Method unkown: "+options.methodphifit))
for n in pool.where("state == 'creating-a-partition'"):
n.state = "created"
n.save()
print "saving " +str(n)
zgf_cleanup.main()