示例#1
0
def main(argv=None):
	if(argv==None):
		argv = sys.argv
	options = options_desc.parse_args(argv)[0]

	assert(not(options.refine_all and options.extend_all)) 
	
	pool = Pool()
	needy_nodes = pool.where("isa_partition and is_sampled").multilock()
	
	# 1. Trying to detect fake convergence
	for n in pool.where("state == 'converged'"):
		means = kmeans(n.trajectory, k=2)
		d = (means[0] - means[1]).norm2()
		if(d > 2.0 and (options.refine_all or userinput("%s has converged but appears to have a bimodal distribution.\nDo you want to refine?"%n.name, "bool"))): #TODO decide upon threshold (per coordinate?)
			refine(n, options)
	
	# 2. Dealing with not-converged nodes
	for n in pool.where("state == 'not-converged'"):
		if(not(options.refine_all or options.extend_all)):
			choice = userchoice("%s has not converged. What do you want to do?"%n.name, ['_refine', '_extend', '_ignore'])
		if(options.refine_all or choice=="r"):
			refine(n, options)
		elif(options.extend_all or choice=="e"):
			extend(n)
		elif(choice=="i"):
			continue
	
	for n in needy_nodes:
		n.save()
		n.unlock()
			
	zgf_setup_nodes.main()
	zgf_grompp.main()
	zgf_cleanup.main()	
示例#2
0
def main():
	pool = Pool()

	if(len(pool.where("state == 'grompp-able'")) > 0):
		call_grompp(pool)
		
	if(len(pool.where("state == 'em-grompp-able'")) > 0):
		assert(path.exists("em.mdp")) #TODO that's not super nice yet
		call_grompp(pool, mode='em')
示例#3
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    zgf_cleanup.main()

    pool = Pool()

    not_reweightable = "isa_partition and state not in ('converged'"
    if (options.ignore_convergence):
        not_reweightable += ",'not-converged'"
    if (options.ignore_failed):
        not_reweightable += ",'mdrun-failed'"
    not_reweightable += ")"

    if pool.where(not_reweightable):
        print "Pool can not be reweighted due to the following nodes:"
        for bad_guy in pool.where(not_reweightable):
            print "Node %s with state %s." % (bad_guy.name, bad_guy.state)
        sys.exit("Aborting.")

    active_nodes = pool.where("isa_partition and state != 'mdrun-failed'")
    assert (len(active_nodes) == len(active_nodes.multilock())
            )  # make sure we lock ALL nodes

    if (options.check_restraint):
        for n in active_nodes:
            check_restraint_energy(n)

    if (options.method == "direct"):
        reweight_direct(active_nodes, options)
    elif (options.method == "entropy"):
        reweight_entropy(active_nodes, options)
    elif (options.method == "presampling"):
        reweight_presampling(active_nodes, options)
    else:
        raise (Exception("Method unkown: " + options.method))

    weight_sum = np.sum([n.tmp['weight'] for n in active_nodes])

    print "Thermodynamic weights calculated by method '%s':" % options.method
    for n in active_nodes:
        n.obs.weight_direct = n.tmp['weight'] / weight_sum
        if (options.method == "direct"):
            print(
                "  %s with mean_V: %f [kJ/mol], %d refpoints and weight: %f" %
                (n.name, n.obs.mean_V, n.tmp['n_refpoints'],
                 n.obs.weight_direct))
        else:
            print("  %s with A: %f [kJ/mol] and weight: %f" %
                  (n.name, n.obs.A, n.obs.weight_direct))
    print "The above weighting uses bonded energies='%s' and nonbonded energies='%s'." % (
        options.e_bonded, options.e_nonbonded)

    for n in active_nodes:
        n.save()

    active_nodes.unlock()
示例#4
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	zgf_cleanup.main()
	
	pool = Pool()

	#not_reweightable = "state not in ('refined','converged')"
	not_reweightable = "isa_partition and state!='converged'"
	if options.ignore_convergence:
		not_reweightable = "isa_partition and state not in ('converged','not-converged')"

	if pool.where(not_reweightable):
		print "Pool can not be reweighted due to the following nodes:"		
		for bad_guy in pool.where(not_reweightable):
			print "Node %s with state %s."%(bad_guy.name, bad_guy.state)
		sys.exit("Aborting.")
		
	active_nodes = pool.where("isa_partition")
	assert(len(active_nodes) == len(active_nodes.multilock())) # make sure we lock ALL nodes

	for n in active_nodes:
		check_restraint_energy(n)

	# find out about number of energygrps
	mdp_file = gromacs.read_mdp_file(pool.mdp_fn)
	energygrps = [str(egrp) for egrp in re.findall('[\S]+', mdp_file["energygrps"])]
	moi_energies = True	
	if len(energygrps) < 2:
		moi_energies = False # Gromacs energies are named differently when there are less than two energygrps :(

	if(options.method == "direct"): 
		reweight_direct(active_nodes, moi_energies, options.sol_energy, options.save_refpoints)
	elif(options.method == "entropy"):
		reweight_entropy(active_nodes, moi_energies, options.sol_energy, options.save_refpoints)
	elif(options.method == "presampling"):
		reweight_presampling(active_nodes, options.presamp_temp, moi_energies, options.sol_energy)
	else:
		raise(Exception("Method unkown: "+options.method))
	
	weight_sum = np.sum([n.tmp['weight'] for n in active_nodes])
	
	print "Thermodynamic weights calculated by method '%s' (sol-energy=%s):"%(options.method, options.sol_energy)
	for n in active_nodes:
		n.obs.weight_direct = n.tmp['weight'] / weight_sum
		if(options.method == "direct"):
			print("  %s with mean_V: %f [kJ/mol], %d refpoints and weight: %f" % (n.name, n.obs.mean_V, n.tmp['n_refpoints'], n.obs.weight_direct))
		else:
			print("  %s with A: %f [kJ/mol] and weight: %f" % (n.name, n.obs.A, n.obs.weight_direct))

	for n in active_nodes:
		n.save()

	active_nodes.unlock()
示例#5
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	zgf_cleanup.main()
	
	pool = Pool()

	not_reweightable = "isa_partition and state not in ('converged'"
	if(options.ignore_convergence):
		not_reweightable += ",'not-converged'"
	if(options.ignore_failed):
		not_reweightable += ",'mdrun-failed'"
	not_reweightable += ")"

	if pool.where(not_reweightable):
		print "Pool can not be reweighted due to the following nodes:"		
		for bad_guy in pool.where(not_reweightable):
			print "Node %s with state %s."%(bad_guy.name, bad_guy.state)
		sys.exit("Aborting.")

	active_nodes = pool.where("isa_partition and state != 'mdrun-failed'")
	assert(len(active_nodes) == len(active_nodes.multilock())) # make sure we lock ALL nodes

	if(options.check_restraint):
		for n in active_nodes:
			check_restraint_energy(n)

	if(options.method == "direct"):
		reweight_direct(active_nodes, options)
	elif(options.method == "entropy"):
		reweight_entropy(active_nodes, options)
	elif(options.method == "presampling"):
		reweight_presampling(active_nodes, options)
	else:
		raise(Exception("Method unkown: "+options.method))
	
	weight_sum = np.sum([n.tmp['weight'] for n in active_nodes])
	
	print "Thermodynamic weights calculated by method '%s':"%options.method
	for n in active_nodes:
		n.obs.weight_direct = n.tmp['weight'] / weight_sum
		if(options.method == "direct"):
			print("  %s with mean_V: %f [kJ/mol], %d refpoints and weight: %f" % (n.name, n.obs.mean_V, n.tmp['n_refpoints'], n.obs.weight_direct))
		else:
			print("  %s with A: %f [kJ/mol] and weight: %f" % (n.name, n.obs.A, n.obs.weight_direct))
	print "The above weighting uses bonded energies='%s' and nonbonded energies='%s'."%(options.e_bonded, options.e_nonbonded)

	for n in active_nodes:
		n.save()

	active_nodes.unlock()
示例#6
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    pool = Pool()

    choice = "state in ('converged', 'refined')"
    if (options.ignore_convergence):
        choice = "state in ('converged', 'not-converged', 'refined')"

    needy_nodes = NodeList([
        n for n in pool.where(choice) if not n == pool.root
    ])  # we won't touch the root

    if not (len(needy_nodes)):
        sys.exit("Nothing to do.")

    if not (userinput(
            "Once the solvent has been removed, further refinement of the pool is not possible. This includes the generation of unrestrained transition nodes! Continue?",
            "bool")):
        sys.exit("Quit by user.")

    assert (len(needy_nodes) == len(needy_nodes.multilock())
            )  # make sure we lock ALL nodes

    try:
        for n in needy_nodes:
            discard_solvent(n, "pdb")
            discard_solvent(n, "trr")

        for n in needy_nodes:
            n.unlock()
    except:
        traceback.print_exc()
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()
	
	choice = "state in ('converged', 'refined')"
	if(options.ignore_convergence):
		choice = "state in ('converged', 'not-converged', 'refined')"	

	needy_nodes = NodeList([n for n in pool.where(choice) if not n == pool.root]) # we won't touch the root

	if not(len(needy_nodes)):
		sys.exit("Nothing to do.")

	if not(userinput("Once the solvent has been removed, further refinement of the pool is not possible. This includes the generation of unrestrained transition nodes! Continue?", "bool")):
		sys.exit("Quit by user.")
		
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes

	try:
		for n in needy_nodes:	
			discard_solvent(n, "pdb")
			discard_solvent(n, "trr")

		for n in needy_nodes:
			n.unlock()
	except:
		traceback.print_exc()
def main():

	options = options_desc.parse_args(sys.argv)[0]
	pool = Pool()

	needy_nodes = pool.where("state == 'merge-able'").multilock()

	if(len(needy_nodes) == 0):
		return
	
	# find out about trr time step
	dt = 0	
	nodeDir = needy_nodes[0].dir.split('/')[-1]
	for fn in os.listdir(needy_nodes[0].dir):
		if re.match("^"+nodeDir+".+run\d+\.trr", fn):
			trr = TrrFile(needy_nodes[0].dir+"/"+fn)			
			dt = trr.first_frame.next().t - trr.first_frame.t
			trr.close()
			break

	# dt is sometimes noisy in the final digits (three digits is femtosecond step = enough)
	dt = np.around(dt, decimals=3)
	for n in needy_nodes:

		if(options.trr):
			# merge sampling trajectories
			trr_fns = sorted([ fn for fn in os.listdir(n.dir) if re.match("[^#].+run\d+.trr", fn) ])
			cmd = ["trjcat", "-f"]
			cmd += trr_fns
			cmd += ["-o", "../../"+n.trr_fn, "-cat"]
			print("Calling: %s"%" ".join(cmd))
			check_call(cmd, cwd=n.dir)

		if(options.edr):
			# merge edr files
			# get list of edr-files
			edr_fnames = sorted([n.dir+"/"+fn for fn in os.listdir(n.dir) if re.match("[^#].+run\d+.edr", fn)])
			assert( len(edr_fnames) ==  n.extensions_counter+1 )
			assert( len(edr_fnames) ==  n.extensions_max+1 )

			time_offset = n.sampling_length+dt

			for edr_fn in edr_fnames[1:]:	
				# adapt edr starting times
				cmd = ["eneconv", "-f", edr_fn, "-o", edr_fn, "-settime"]
				print("Calling: "+(" ".join(cmd)))
				p = Popen(cmd, stdin=PIPE)
				p.communicate(input=(str(time_offset)+"\n"))
				assert(p.wait() == 0)

				time_offset += n.extensions_length+dt

			# concatenate edr files with adapted starting times
			cmd = ["eneconv", "-f"] + edr_fnames + ["-o", n.dir+"/ener.edr"]
			print("Calling: "+(" ".join(cmd)))
			p = Popen(cmd)
			retcode = p.wait()
			assert(retcode == 0)

	needy_nodes.unlock()
示例#9
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	pool = Pool()
	
	if(options.convtest):
		for n in pool.where("state in ('converged', 'not-converged')"):
			print("\n\nRunning Gelman-Rubin on %s"%n)
			conv_check_gelman_rubin(n)
		return # exit

	auto_refines_counter = 0
	while(True):		
		pool.reload()
		pool.reload_nodes()
		for n in pool:
			n.reload()

		active_node = None
		for n in pool.where("state in ('em-mdrun-able', 'mdrun-able', 'rerun-able-converged', 'rerun-able-not-converged')"):
			if(n.lock()):
				active_node = n
				break

		if(active_node == None):
			if(auto_refines_counter < options.auto_refines):
				auto_refines_counter += 1
				print("\n\nRunning 'zgf_refine --refine-all' for the %d time..."%auto_refines_counter)
				zgf_refine.main(["--refine-all"])
				continue
			else:
				break # we're done - exit
	
		try:
			process(active_node, options)
			active_node.save()
			active_node.unlock()
		except:
			print "MDRUN FAILED"
			active_node.state = "mdrun-failed"
			active_node.save()
			active_node.unlock()
			traceback.print_exc()
			continue
示例#10
0
def main():
    pool = Pool()
    needy_nodes = pool.where("state == 'grompp-able'").multilock()

    try:
        for n in needy_nodes:
            call_grompp(n)
    except:
        traceback.print_exc()

    for n in needy_nodes:
        n.unlock()
示例#11
0
def main():
	pool = Pool()
	needy_nodes = pool.where("state == 'grompp-able'").multilock()
		
	try:
		for n in needy_nodes:
			call_grompp(n)			
	except:
		traceback.print_exc()

	for n in needy_nodes:
		n.unlock()
示例#12
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    pool = Pool()
    needy_nodes = pool.where("state == 'grompp-able'")
    assert (len(needy_nodes) == len(needy_nodes.multilock())
            )  # make sure we lock ALL nodes

    if (options.solv_model == "tip3p"):
        solv_box = "spc216.gro"
        solv_fn = "tip3p.itp"
    elif (options.solv_model == "tip4p"):
        solv_box = "tip4p.gro"
        solv_fn = "tip4p.itp"
    elif (options.solv_model == "tip4pew"):
        solv_box = "tip4p.gro"
        solv_fn = "tip4pew.itp"
    elif (options.solv_model == "tip5"):
        solv_box = "tip5p.gro"
        solv_fn = "tip5p.itp"
    elif (options.solv_model == "spc"):
        solv_box = "spc216.gro"
        solv_fn = "spc.itp"
    elif (options.solv_model == "spce"):
        solv_box = "spc216.gro"
        solv_fn = "spce.itp"
    elif (
            options.solv_model == "acetonitrile"
    ):  # TODO one might change this one to "custom" and let user enter name of template box
        solv_box = "acetonitrile.pdb"
        msg = "Topology update for acetonitrile is not supported. Proceed?"
        if not (userinput(msg, "bool")):
            for n in needy_nodes:
                n.unlock()
            return ("Quit by user.")

    # determine maximum length of linears, if any
    max_linear = query_linear_length(pool)

    # make box and fill with solvent
    genbox(pool, max_linear, options.bt,
           (options.box_x, options.box_y, options.box_z), solv_box)

    # update topology files (add solvent model and ions includes)
    if not (options.solv_model == "acetonitrile"):
        update_tops(pool, solv_fn)

    for n in needy_nodes:
        n.state = "em-grompp-able"
        zgf_grompp.call_grompp(
            n, mdp_file=options.grompp, final_state="em-mdrun-able"
        )  # re-grompp to get a tpr for energy minimization
        n.unlock()
示例#13
0
def main(argv=None):
    if (argv == None):
        argv = sys.argv
    options = options_desc.parse_args(argv)[0]

    assert (not (options.refine_all and options.extend_all))

    pool = Pool()
    needy_nodes = pool.where("isa_partition and is_sampled").multilock()

    # 1. Trying to detect fake convergence
    for n in pool.where("state == 'converged'"):
        means = kmeans(n.trajectory, k=2)
        d = (means[0] - means[1]).norm2()
        if (d > 2.0 and (options.refine_all or userinput(
                "%s has converged but appears to have a bimodal distribution.\nDo you want to refine?"
                % n.name,
                "bool"))):  #TODO decide upon threshold (per coordinate?)
            refine(n, options)

    # 2. Dealing with not-converged nodes
    for n in pool.where("state == 'not-converged'"):
        if (not (options.refine_all or options.extend_all)):
            choice = userchoice(
                "%s has not converged. What do you want to do?" % n.name,
                ['_refine', '_extend', '_ignore'])
        if (options.refine_all or choice == "r"):
            refine(n, options)
        elif (options.extend_all or choice == "e"):
            extend(n)
        elif (choice == "i"):
            continue

    for n in needy_nodes:
        n.save()
        n.unlock()

    zgf_setup_nodes.main()
    zgf_grompp.main()
    zgf_cleanup.main()
示例#14
0
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()	
示例#15
0
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()	
示例#16
0
def main():
	
	pool = Pool()
	needy_nodes = pool.where("state == 'created'")
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes 
	
	extract_frames(pool)
	generate_topology(pool)
	generate_mdp(pool)
	
	for n in needy_nodes:
		n.state = "grompp-able"
		n.save()
		n.unlock()
示例#17
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	zgf_cleanup.main()

	pool = Pool()

	needy_nodes = pool.where("state == '%s'"%options.current_state).multilock()

	for n in needy_nodes:
		print "Recovering node %s with state %s to state %s ..."%(n.name, n.state, options.recover_state)
		n.state = options.recover_state
		n.save()		
		n.unlock()
示例#18
0
def main():

    pool = Pool()
    needy_nodes = pool.where("state == 'created'")
    assert (len(needy_nodes) == len(needy_nodes.multilock())
            )  # make sure we lock ALL nodes

    extract_frames(pool)
    generate_topology(pool)
    generate_mdp(pool)

    for n in needy_nodes:
        n.state = "grompp-able"
        n.save()
        n.unlock()
示例#19
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    zgf_cleanup.main()

    pool = Pool()

    needy_nodes = pool.where("state == '%s'" %
                             options.current_state).multilock()

    for n in needy_nodes:
        print "Recovering node %s with state %s to state %s ..." % (
            n.name, n.state, options.recover_state)
        n.state = options.recover_state
        n.save()
        n.unlock()
示例#20
0
def main():
	options = options_desc.parse_args(sys.argv)[0]

	outfile = open(options.outfile,"w")
	
	pool = Pool()
	needy_nodes = pool.where("isa_partition and state not in ('refined','mdrun-failed')")
	
	for n in needy_nodes:
		outfile.write("%s, state: '%s':\n"%(n.name,n.state))
		outfile.write(str(n.internals.array)+"\n")
		outfile.write("mean pot.: %f, std pot.: %f, free energy estimate: %f\n"%(n.obs.mean_V,n.obs.std_V,n.obs.A))
		outfile.write("#========================================================================#\n")

	outfile.close()
	print "Pool info was written to %s."%options.outfile
示例#21
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()
	needy_nodes = pool.where("state == 'em-mdrun-able'")
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes


	# add ions to simulation boxes
	call_genion(pool, options.np, options.pname, options.nn, options.nname, options.random_seed)

	
	for n in needy_nodes:
		n.state = "em-grompp-able"
		zgf_grompp.call_grompp(n, mdp_file=options.grompp, final_state="em-mdrun-able") # re-grompp to get a tpr for energy minimization
		n.unlock()
示例#22
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()
	needy_nodes = pool.where("state == 'grompp-able'")
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes

	if(options.solv_model == "tip3p"):
		solv_box = "spc216.gro"
		solv_fn = "tip3p.itp"
	elif(options.solv_model == "tip4p"):
		solv_box = "tip4p.gro"
		solv_fn = "tip4p.itp"
	elif(options.solv_model == "tip4pew"):
		solv_box = "tip4p.gro"
		solv_fn = "tip4pew.itp"
	elif(options.solv_model == "tip5"):
		solv_box = "tip5p.gro"
		solv_fn = "tip5p.itp"
	elif(options.solv_model == "spc"):
		solv_box = "spc216.gro"
		solv_fn = "spc.itp"
	elif(options.solv_model == "spce"):
		solv_box = "spc216.gro"
		solv_fn = "spce.itp"
	elif(options.solv_model == "acetonitrile"): # TODO one might change this one to "custom" and let user enter name of template box
		solv_box = "acetonitrile.pdb"
		msg = "Topology update for acetonitrile is not supported. Proceed?"
		if not(userinput(msg, "bool")):
			for n in needy_nodes:
				n.unlock()
			return("Quit by user.")
	
	# determine maximum length of linears, if any
	max_linear = query_linear_length(pool)

	# make box and fill with solvent
	genbox(pool, max_linear, options.bt, (options.box_x, options.box_y, options.box_z), solv_box)

	# update topology files (add solvent model and ions includes)
	if not(options.solv_model == "acetonitrile"):
		update_tops(pool, solv_fn)

	for n in needy_nodes:
		n.state = "em-grompp-able"
		zgf_grompp.call_grompp(n, mdp_file=options.grompp, final_state="em-mdrun-able") # re-grompp to get a tpr for energy minimization
		n.unlock()
示例#23
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()
	needy_nodes = pool.where("state == 'em-mdrun-able'")
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes


	# add ions to simulation boxes
	call_genion(pool, options.np, options.pname, options.nn, options.nname, options.random_seed)

	
	for n in needy_nodes:
		n.state = "em-grompp-able"
		n.save()
		n.unlock()

	zgf_grompp.main()
示例#24
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    pool = Pool()
    needy_nodes = pool.where("state == 'em-mdrun-able'")
    assert (len(needy_nodes) == len(needy_nodes.multilock())
            )  # make sure we lock ALL nodes

    # add ions to simulation boxes
    call_genion(pool, options.np, options.pname, options.nn, options.nname,
                options.random_seed)

    for n in needy_nodes:
        n.state = "em-grompp-able"
        zgf_grompp.call_grompp(
            n, mdp_file=options.grompp, final_state="em-mdrun-able"
        )  # re-grompp to get a tpr for energy minimization
        n.unlock()
示例#25
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    outfile = open(options.outfile, "w")

    pool = Pool()
    needy_nodes = pool.where(
        "isa_partition and state not in ('refined','mdrun-failed')")

    for n in needy_nodes:
        outfile.write("%s, state: '%s':\n" % (n.name, n.state))
        outfile.write(str(n.internals.array) + "\n")
        outfile.write(
            "mean pot.: %f, std pot.: %f, free energy estimate: %f\n" %
            (n.obs.mean_V, n.obs.std_V, n.obs.A))
        outfile.write(
            "#========================================================================#\n"
        )

    outfile.close()
    print "Pool info was written to %s." % options.outfile
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()
	needy_nodes = pool.where("state == 'grompp-able'")
	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes

	if(options.solv_model == "tip3p"):
		solv_box = "spc216.gro"
		solv_fn = "tip3p.itp"
	elif(options.solv_model == "tip4p"):
		solv_box = "tip4p.gro"
		solv_fn = "tip4p.itp"
	elif(options.solv_model == "tip4pew"):
		solv_box = "tip4p.gro"
		solv_fn = "tip4pew.itp"
	elif(options.solv_model == "tip5"):
		solv_box = "tip5p.gro"
		solv_fn = "tip5p.itp"
	elif(options.solv_model == "spc"):
		solv_box = "spc216.gro"
		solv_fn = "spc.itp"
	elif(options.solv_model == "spce"):
		solv_box = "spc216.gro"
		solv_fn = "spce.itp"
	
	# determine maximum length of linears, if any
	max_linear = query_linear_length(pool)

	# make box and fill with solvent
	genbox(pool, max_linear, options.bt, (options.box_x, options.box_y, options.box_z), solv_box)

	# update topology files (add solvent model and ions includes)
	update_tops(pool, solv_fn)

	for n in needy_nodes:
		n.state = "em-grompp-able"
		n.save()
		n.unlock()
示例#27
0
def is_applicable():
	pool = Pool()
	return(len(pool.where("state == 'grompp-able'")) > 0 or len(pool.where("state == 'em-grompp-able'")) > 0)
示例#28
0
def is_applicable():
    pool = Pool()
    return (len(pool.where("isa_partition and is_sampled")) > 0)
示例#29
0
def main():
	options = options_desc.parse_args(sys.argv)[0]

	pool = Pool()
	active_nodes = pool.where("isa_partition")

	if options.transition_level == "clusters":
		npz_file = np.load(pool.chi_mat_fn)
		chi_matrix = npz_file['matrix']
		n_clusters = npz_file['n_clusters']

		default_cluster_threshold = options.coreset_power

		# determine cluster
		#TODO this part is too cryptic
		# amount_phi[j] = amount of basis functions per cluster j
		amount_phi=np.ones(n_clusters,dtype=np.uint64)
		amount_phi=amount_phi*len(chi_matrix)
		amount_phi_total=len(chi_matrix)	

		# sort columns of chi and return new sorted args
		arg_sort_cluster=np.argsort(chi_matrix,axis=0)
		# sort columns of chi and return new sorted chi
		# notice that the last row has to be [1 ... 1]
		sort_cluster=np.sort(chi_matrix,axis=0)
		# show_cluster contains arrays of the type [a b] where a is the row
		# and b the column of the entry from chi matrix  where 
		# chi_sorted(a,b) > default_cluster_threshold
		show_cluster=np.argwhere(sort_cluster > 0.5 )

		# from the above it could be clear
		# that the amount of phi function
		# of cluster i is given by x where x the number so that 
		# [x i] is in show_cluster and for all 
		# [y i] in show_cluster we have x>y 
		# we define amount_phi[i]=x	
		for element in show_cluster:
			index=element[0]
			cluster=element[1]
			if amount_phi[cluster]>index:
				amount_phi[cluster]=index

		# create cluster list which contains arrays
		# each array consinst of a set of numbers corresponding to 
		# the phi function of node_number
		cluster=[]
		for i in range(0,n_clusters):
			cluster_set=[]		
			for j in range(amount_phi[i],amount_phi_total):
				#if (j < amount_phi[i] + 3):
					cluster_set.append(arg_sort_cluster[j][i])	
			cluster.append(cluster_set)

		for i in range(len(cluster)):
			counter = 0
			for node_index in cluster[i]:
				counter += 1
				# and ignore nodes which have a higher chi value then default_cluster_threshold
				if( chi_matrix[node_index][i] > default_cluster_threshold and counter>options.min_nodes):
					continue
				
				node = active_nodes[node_index]
				trajectory= node.trajectory
			
				print "-----"
				print "Generating transition nodes for node %s..."%node.name
			
				neighbour_frames = get_indices_equidist(node, options.num_tnodes)
		
				# create transition node for node_index
				for frame_number in neighbour_frames:
					print "Using frame %d as starting configuration."%frame_number
					n = Node()
					n.parent_frame_num = frame_number
					n.parent = node
					n.state = "created"
					n.extensions_counter = 0
					n.extensions_max = options.num_runs-1
					n.extensions_length = options.sampling_length
					n.sampling_length = options.sampling_length
					n.internals = trajectory.getframe(frame_number)
					n.save_mode = options.save_mode
					pool.append(n)
					n.save()
				print "%d transition nodes generated."%options.num_tnodes
				print "-----"

		zgf_setup_nodes.main()
		zgf_grompp.main()
	
		cluster_dict = {}
		for (ic,c) in enumerate(cluster):
			cluster_dict['cluster_%d'%ic] = c

		# save cluster
		np.savez(pool.analysis_dir+"core_set_cluster.npz", **cluster_dict)

	elif options.transition_level == "nodes":
		for node in active_nodes:
			trajectory= node.trajectory
			
			# TODO duplicate code... use the one above
			print "-----"
			print "Generating transition nodes for node %s..."%node.name

			neighbour_frames = get_indices_equidist(node, options.num_tnodes)

			# create transition point for node_index
			for frame_number in neighbour_frames:
				print "Using frame %d as starting configuration."%frame_number
				n = Node()
				n.parent_frame_num = frame_number
				n.parent = node
				n.state = "created"
				n.extensions_counter = 0
				n.extensions_max = options.num_runs-1
				n.extensions_length = options.sampling_length
				n.sampling_length = options.sampling_length
				n.internals = trajectory.getframe(frame_number)
				n.save_mode = options.save_mode
				pool.append(n)
				n.save()
			print "%d transition nodes generated."%options.num_tnodes
			print "-----"

		zgf_setup_nodes.main()
		zgf_grompp.main()


	instructionFile = pool.analysis_dir+"instruction.txt"

	f = open(instructionFile, "w")
	f.write("{'power': %f, 'tnodes': %d, 'level': '%s', 'min_nodes': %d}"%(options.coreset_power, options.num_tnodes, options.transition_level, options.min_nodes))
	f.close()
示例#30
0
def is_applicable():
    pool = Pool()
    return (pool.where("isa_partition and state != 'mdrun-failed'") > 0)
示例#31
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	zgf_cleanup.main()
	
	print("Options:\n%s\n"%pformat(eval(str(options))))
	
	pool = Pool()
	parent = pool.root
	active_nodes = pool.where("isa_partition")
	
	assert(len(active_nodes) == len(active_nodes.multilock())) # make sure we lock ALL nodes

	if active_nodes.where("'weight_direct' not in obs"):
		sys.exit("Q-Matrix calculation not possible: Not all of the nodes have been reweighted.")

	node_weights = np.array([node.obs.weight_direct for node in active_nodes])
	
	print "### Generate bins: equidist ###" 
	result = q_equidist(parent, options.numnodes)
	chosen_idx=result['chosen_idx']
	frames_chosen=result['frames_chosen']
	theta=result['theta']
	chosen_idx.sort() # makes preview-trajectory easier to understand
	dimension=len(chosen_idx)

	print "chosen_idx"
	print chosen_idx

	print "### Generate bin weights ###"
	bin_weights=np.zeros(dimension)
	for (i,n) in enumerate(active_nodes):
		w_denom = np.sum(n.frameweights) 
		for t in range(len(n.trajectory)):
			diffs = (frames_chosen - n.trajectory.getframe(t)).norm()
			j = np.argmin(diffs)
			bin_weights[j] = bin_weights[j] + node_weights[i] * n.frameweights[t] / w_denom
			
	
	print "bin_weights"
	print bin_weights
	
	print "### Generate q_all (entries only for neighboring bins) ###" 
	q_all = np.empty((dimension, dimension), dtype=np.float)
	for i in range(dimension):
		sum_row = 0.0
		diffs = (frames_chosen - frames_chosen.getframe(i)).norm()
		print "diffs"
		print diffs
		for j in range(dimension):
			if (diffs[j] < 2.0 * theta) and (bin_weights[i] > 0.0):
				q_all[i,j] = np.sqrt(bin_weights[j]) / np.sqrt(bin_weights[i])
				sum_row = sum_row + q_all[i , j]
			else:
				q_all[i,j] = 0
		q_all[i, i] = q_all[i, i]- sum_row  
			
	print "Q_All"
	print q_all
	
	if options.export_matlab:
		savemat(pool.analysis_dir+"q_all.mat", {"q_all":q_all})
		
	active_nodes.unlock()
	zgf_cleanup.main()
def is_applicable():
	pool = Pool()
	return(len(pool.where("state=='mdrun-able'")) > 0)
示例#33
0
def is_applicable():
	pool = Pool()
	return( len(pool.where("'weight_direct' in obs")) > 0 and len(pool.where("isa_partition and 'weight_direct' not in obs")) == 0 )
示例#34
0
def is_applicable():
	pool = Pool()
	return(len(pool.where("state in ('em-mdrun-able', 'mdrun-able', 'converged', 'not-converged', 'rerun-able-converged', 'rerun-able-not-converged')")) > 0)
示例#35
0
def is_applicable():
    pool = Pool()
    return (len(pool) > 1 and len(
        pool.where(
            "isa_partition and state in ('converged','not-converged','mdrun-failed')"
        )) == len(pool.where("isa_partition")))
示例#36
0
def is_applicable():
    pool = Pool()
    return (len(pool.where("state == 'em-mdrun-able'")) > 0)
示例#37
0
def is_applicable():
	pool = Pool()
	return( len(pool.where("'weight_direct' in obs")) > 0 and len(pool.where("isa_partition and 'weight_direct' not in obs")) == 0 )
示例#38
0
def is_applicable():
    pool = Pool()
    return (len(pool.where("state == 'grompp-able'")) > 0)
示例#39
0
def is_applicable():
	pool = Pool()
	return(len(pool.where("state == 'created'")) > 0)
示例#40
0
def is_applicable():
	pool = Pool()
	return( len(pool.where("state in ('converged', 'not-converged', 'refined')")) > 1 )
示例#41
0
def main():
	options = options_desc.parse_args(sys.argv)[0]

	zgf_cleanup.main()
	
	pool = Pool()
	active_nodes = pool.where("isa_partition")
	if(options.ignore_failed):
			active_nodes = pool.where("isa_partition and not state=='mdrun-failed'")

	assert(len(active_nodes) == len(active_nodes.multilock())) # make sure we lock ALL nodes

	if active_nodes.where("'weight_direct' not in obs"):
		active_nodes.unlock()
		sys.exit("Matrix calculation not possible: Not all of the nodes have been reweighted.")
	
	print "\n### Getting S matrix ..."
	s_matrix = cache_matrix(pool.s_mat_fn, active_nodes, overwrite=options.overwrite_mat, fast=options.fast_mat)
	register_file_dependency(pool.s_mat_fn, pool.filename)

	node_weights = np.array([node.obs.weight_direct for node in active_nodes])
	
	print "\n### Symmetrizing S matrix ..."
	(corr_s_matrix, corr_node_weights) = symmetrize(s_matrix, node_weights, correct_weights=True, error=float(options.error))

	# store intermediate results
	register_file_dependency(pool.s_corr_mat_fn, pool.s_mat_fn)

	np.savez(pool.s_corr_mat_fn, matrix=corr_s_matrix, node_names=[n.name for n in active_nodes])
	
	if options.export_matlab:
		savemat(pool.analysis_dir+"node_weights.mat", {"node_weights":node_weights, "node_weights_corrected":corr_node_weights})
		savemat(pool.analysis_dir+"s_mats.mat", {"s_matrix":s_matrix, "s_matrix_corrected":corr_s_matrix})

	for (n, cw) in zip(active_nodes, corr_node_weights):
		n.obs.weight_corrected = cw
		
	print "\n### Node weights after symmetrization of S matrix:"
	for n in active_nodes:
		print "%s: initial weight: %f, corrected weight: %f, weight change: %f" % (n.name, n.obs.weight_direct, n.obs.weight_corrected, abs(n.obs.weight_direct - n.obs.weight_corrected))
		n.save()

	active_nodes.unlock()

	# calculate and sort eigenvalues in descending order
	(eigvalues, eigvectors) = np.linalg.eig(corr_s_matrix)
	argsorted_eigvalues = np.argsort(-eigvalues)
	eigvalues = eigvalues[argsorted_eigvalues]
	eigvectors = eigvectors[:, argsorted_eigvalues]
	
	gaps = np.abs(eigvalues[1:]-eigvalues[:-1])
	gaps = np.append(gaps, 0.0)
	wgaps = gaps*eigvalues

	print "\n### Sorted eigenvalues of symmetrized S matrix:"
	for (idx, ev, gap, wgap) in zip(range(1, len(eigvalues)+1), eigvalues, gaps, wgaps):
		print "EV%04d: %f, gap to next: %f, EV-weighted gap to next: %f" % (idx, ev, gap, wgap)
	n_clusters = np.argmax(wgaps)+1
	print "\n### Maximum gap %f after top %d eigenvalues." % (np.max(gaps), n_clusters)
	print "### Maximum EV-weighted gap %f after top %d eigenvalues." % (np.max(wgaps), np.argmax(wgaps)+1)
	sys.stdout.flush()
	if not options.auto_cluster:
		n_clusters = userinput("Please enter the number of clusters for PCCA+", "int", "x>0")
	print "### Using %d clusters for PCCA+ ..."%n_clusters

	if options.export_matlab:
		savemat(pool.analysis_dir+"evs.mat", {"evs":eigvectors})
	
	# orthogonalize and normalize eigenvectors 
	eigvectors = orthogonalize(eigvalues, eigvectors, corr_node_weights)

	# perform PCCA+
	# First two return-values "c_f" and "indicator" are not needed
	(chi_matrix, rot_matrix) = cluster_by_isa(eigvectors, n_clusters)[2:]

	if(options.optimize_chi):
		print "\n### Optimizing chi matrix ..."
		
		outliers = 5
		mean_weight = np.mean(corr_node_weights)
		threshold = mean_weight/100*outliers
		print "Light-weight node threshold (%d%% of mean corrected node weight): %.4f."%(outliers, threshold)

		# accumulate nodes for optimization
		edges = np.where(np.max(chi_matrix, axis=1) > 0.9999)[0] # edges of simplex
		heavies = np.where( corr_node_weights > threshold)[0] # heavy-weight nodes
		filtered_eigvectors = eigvectors[ np.union1d(edges, heavies) ]

		# perform the actual optimization
		rot_matrix = opt_soft(filtered_eigvectors, rot_matrix, n_clusters)

		chi_matrix = np.dot(eigvectors[:,:n_clusters], rot_matrix)
		
		# deal with light-weight nodes: shift and scale
		for i in np.where(corr_node_weights <= threshold)[0]:
			if(i in edges):
				print "Column %d belongs to (potentially dangerous) light-weight node, but its node is a simplex edge."%(i+1)
				continue
			print "Column %d is shifted and scaled."%(i+1)
			col_min = np.min( chi_matrix[i,:] )
			chi_matrix[i,:] -= col_min
			chi_matrix[i,:] /= 1-(n_clusters*col_min)
			
	qc_matrix = np.dot( np.dot( np.linalg.inv(rot_matrix), np.diag(eigvalues[range(n_clusters)]) ), rot_matrix ) - np.eye(n_clusters)
	cluster_weights = rot_matrix[0]
	
	print "\n### Matrix numerics check"
	print "-- Q_c matrix row sums --"
	print np.sum(qc_matrix, axis=1)
	print "-- cluster weights: first column of rot_matrix --"
	print cluster_weights
	print "-- cluster weights: numpy.dot(node_weights, chi_matrix) --"
	print np.dot(corr_node_weights, chi_matrix)
	print "-- chi matrix column max values --"
	print np.max(chi_matrix, axis=0)
	print "-- chi matrix row sums --"
	print np.sum(chi_matrix, axis=1)

	# store final results
	np.savez(pool.chi_mat_fn, matrix=chi_matrix, n_clusters=n_clusters, node_names=[n.name for n in active_nodes])
	np.savez(pool.qc_mat_fn,  matrix=qc_matrix,  n_clusters=n_clusters, node_names=[n.name for n in active_nodes], weights=cluster_weights)

	if options.export_matlab:		
		savemat(pool.analysis_dir+"chi_mat.mat", {"chi_matrix":chi_matrix})
		savemat(pool.analysis_dir+"qc_mat.mat", {"qc_matrix":qc_matrix, "weights":cluster_weights})

	register_file_dependency(pool.chi_mat_fn, pool.s_corr_mat_fn)
	register_file_dependency(pool.qc_mat_fn, pool.s_corr_mat_fn)

	for fn in (pool.s_mat_fn, pool.s_corr_mat_fn):
		register_file_dependency(pool.chi_mat_fn, fn)
		register_file_dependency(pool.qc_mat_fn, fn)

	# touch analysis directory (triggering update in zgf_browser)
	atime = mtime = time.time()
	os.utime(pool.analysis_dir, (atime, mtime))

	# show summary
	if(options.summary):
		print "\n### Preparing cluster summary ..."
		chi_threshold = 1E-3
		from pprint import pformat
	
		for i in range(n_clusters):
			involved_nodes = [active_nodes[ni] for ni in np.argwhere(chi_matrix[:,i] > chi_threshold)]
			max_chi_node = active_nodes[ np.argmax(chi_matrix[:,i]) ]
			c_max = []

			for c in  pool.converter:
				coord_range = pool.coord_range(c)
				scale = c.plot_scale
				edges = scale(np.linspace(np.min(coord_range), np.max(coord_range), num=50))
				hist_cluster = np.zeros(edges.size-1)

				for (n, chi) in zip([n for n in active_nodes], chi_matrix[:,i]):
					samples = scale( n.trajectory.getcoord(c) )
					hist_node = np.histogram(samples, bins=edges, weights=n.frameweights, normed=True)[0]
					hist_cluster += n.obs.weight_corrected * hist_node * chi

				c_max.append( scale(np.linspace(np.min(coord_range), np.max(coord_range), num=50))[np.argmax(hist_cluster)] )

			msg = "### Cluster %d (weight=%.4f, #involved nodes=%d, representative='%s'):"%(i+1, cluster_weights[i], len(involved_nodes), max_chi_node.name)
			print "\n"+msg
			print "-- internal coordinates --"
			print "%s"%pformat(["%.2f"%cm for cm in c_max])
			print "-- involved nodes --"
			print "%s"%pformat([n.name for n in involved_nodes])			
			print "-"*len(msg)
示例#42
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    pool = Pool()
    active_nodes = pool.where("isa_partition")

    # check if zgf_create_tnodes was executed before
    assert (os.path.exists(pool.analysis_dir + "instruction.txt"))
    try:
        f = open(pool.analysis_dir + "instruction.txt")
        command = f.read()
        instructions = eval(command)
    except:
        raise (Exception("Could not parse: " + pool.analysis_dir +
                         "instruction.txt"))

    transition_level = instructions['level']
    n_tnodes = instructions['tnodes']

    all_ready_nodes = pool.where("state == 'ready'")
    n_runs = all_ready_nodes[0].extensions_max + 1

    assert (all_ready_nodes[0].sampling_length ==
            all_ready_nodes[0].extensions_length)
    tau = all_ready_nodes[0].sampling_length

    # let's calculate a Pc matrix
    if transition_level == "clusters":
        default_cluster_threshold = instructions['power']
        min_nodes = instructions['min_nodes']

        npz_file = np.load(pool.chi_mat_fn)
        chi_matrix = npz_file['matrix']

        npz_file = np.load(pool.analysis_dir + "core_set_cluster.npz")
        cluster = [npz_file[c] for c in sorted(npz_file.files)]

        Pc = np.zeros(shape=(len(cluster), len(cluster)))

        print "For each node, sample %d tnodes with %d runs" % (n_tnodes,
                                                                n_runs)
        # start calculating matrix
        cluster_index_i = 0  #TODO maker nicer
        for i in range(len(cluster)):
            print "\n CLUSTER %d contains the following nodes:" % i
            print cluster[i]
            counter = 0
            for node_index in cluster[i]:
                counter = counter + 1
                node = active_nodes[node_index]
                frameweights_of_node_i = node.frameweights

                # and nodes which have a higher chi value then default_cluster_threshold
                if (chi_matrix[node_index][i] > default_cluster_threshold
                        and counter > min_nodes):
                    print "Node " + str(
                        node_index
                    )  #TODO this index is not the global node index... somewhat misleading
                    print "chi value: " + str(chi_matrix[node_index][i])
                    print "counter:   " + str(counter)
                    print "cluster:   " + str(cluster_index_i)
                    print "no tnodes"
                    print "- - - -"
                    # for other nodes add corresponding Pc value - assuming those cluster are metastable
                    trajectory = node.trajectory
                    tnode_frames = get_indices_equidist(node, n_tnodes)
                    for frame_number in tnode_frames:
                        # behave like node would not move in simulation
                        weight = frameweights_of_node_i[frame_number]
                        #TODO: add option for calculat Matrix without soft chi_matrix
                        Pc[cluster_index_i,
                           cluster_index_i] += n_runs * weight * node.obs.weight_corrected * chi_matrix[
                               node_index][cluster_index_i] * chi_matrix[
                                   node_index][cluster_index_i]
                    continue

                ready_nodes = pool.where(
                    "state == 'ready' and parent!=None and parent.name=='%s'" %
                    node.name)

                print "Node " + str(
                    node_index
                )  #TODO this index is not the global node index... somewhat misleading
                print "chi value: " + str(chi_matrix[node_index][i])
                print "counter:   " + str(counter)
                print "cluster:   " + str(cluster_index_i)
                print "#tnodes:   " + str(len(ready_nodes))
                print "- - - -"

                for ready_node in ready_nodes:
                    weight = frameweights_of_node_i[
                        ready_node.parent_frame_num]
                    #frame_value = pool.converter.read_pdb(ready_node.pdb_fn)
                    #temp_dist=(frame_value - node_i.internals).norm2()

                    #iterate pdb files
                    for fn in os.listdir(ready_node.dir):
                        if (re.match(".+.pdb", fn)):
                            # add radius feature in future
                            frame_value = pool.converter.read_pdb(
                                ready_node.dir + "/" + fn)
                            #calculate distances
                            temp_val = np.zeros(len(active_nodes))
                            index_temp = 0
                            for node_temp in active_nodes:
                                temp_val[index_temp] = (
                                    frame_value - node_temp.internals).norm2()
                                index_temp = index_temp + 1

                            # which node has closest distance?
                            index_j = np.argsort(temp_val)[0]

                            #which cluster has highest chi value?
                            cluster_index_j = np.argsort(
                                chi_matrix[index_j][:])[len(cluster) - 1]

                            #calc Pc entry
                            Pc[cluster_index_i,
                               cluster_index_j] += weight * node.obs.weight_corrected * chi_matrix[
                                   node_index][cluster_index_i] * chi_matrix[
                                       index_j][cluster_index_j]

            cluster_index_i = cluster_index_i + 1

        for i in range(0, len(cluster)):
            factor = sum(Pc[i, :])
            Pc[i, :] = (1 / factor) * Pc[i, :]

        # store final results
        np.savez(pool.pc_mat_fn,
                 matrix=Pc,
                 node_names=[n.name for n in active_nodes
                             ])  #TODO store additional info?
        if options.export_matlab:
            savemat(pool.analysis_dir + "pc_mat.mat", {"Pc_matrix": Pc})

    # let's calculate a P matrix
    elif transition_level == "nodes":
        P = np.zeros(shape=(len(active_nodes), len(active_nodes)))
        P_hard = np.zeros(shape=(len(active_nodes), len(active_nodes)))

        index_i = 0
        for node_i in active_nodes:
            # get frameweights and ready_nodes
            ready_nodes = pool.where(
                "state == 'ready' and parent!=None and parent.name=='%s'" %
                node_i.name)
            frameweights_of_node_i = node_i.frameweights

            for ready_node in ready_nodes:
                weight = frameweights_of_node_i[ready_node.parent_frame_num]
                frame_value = pool.converter.read_pdb(ready_node.pdb_fn)
                temp_dist = (frame_value - node_i.internals).norm2()

                legal_ready_node = True
                for node_temp in active_nodes:
                    if (temp_dist >
                        (frame_value - node_temp.internals).norm2()):
                        legal_ready_node = False
                        print "strange ready node!"

                #iterate pdb files
                #if(temp_dist <= p_radius):
                if (legal_ready_node):
                    for fn in os.listdir(ready_node.dir):
                        if (re.match("[^#].+.pdb", fn)):
                            # add radius feature in future
                            #print "Filedirectory"
                            #print ready_node.dir+"/"+fn
                            frame_value = pool.converter.read_pdb(
                                ready_node.dir + "/" + fn)
                            #calculate distances
                            temp_val = np.zeros(len(active_nodes))
                            index_temp = 0
                            for node_temp in active_nodes:
                                temp_val[index_temp] = (
                                    frame_value - node_temp.internals).norm2()
                                index_temp = index_temp + 1

                            index_j = np.argsort(temp_val)[0]

                            #calc P entry
                            #if(temp_val[index_j] <= p_radius):
                            P[index_i,
                              index_j] += weight * node_i.obs.weight_corrected
                            P_hard[index_i, index_j] += 1

            index_i = index_i + 1

        for i in range(0, len(active_nodes)):
            factor = sum(P[i, :])
            P[i, :] = (1 / factor) * P[i, :]

        # store final results
        np.savez(pool.p_mat_fn,
                 matrix=P,
                 node_names=[n.name for n in active_nodes
                             ])  #TODO store additional info?
        if options.export_matlab:
            savemat(pool.analysis_dir + "p_mat.mat", {"P_matrix": P})

    if transition_level == "clusters":
        print "Clusters: " + str(cluster)
        print "Transition matrix Pc for tau = %d ps:" % tau
        print Pc
    elif transition_level == "nodes":
        print "Nodes: " + str(active_nodes)
        print "Transition matrix P for tau = %d ps:" % tau
        print P
示例#43
0
def is_applicable():
	pool = Pool()
	return(len(pool.where("isa_partition and is_sampled")) > 0)
def main():

    options = options_desc.parse_args(sys.argv)[0]
    pool = Pool()

    needy_nodes = pool.where("state == 'merge-able'").multilock()

    if (len(needy_nodes) == 0):
        return

    # find out about trr time step
    dt = 0
    nodeDir = needy_nodes[0].dir.split('/')[-1]
    for fn in os.listdir(needy_nodes[0].dir):
        if re.match("^" + nodeDir + ".+run\d+\.trr", fn):
            trr = TrrFile(needy_nodes[0].dir + "/" + fn)
            dt = trr.first_frame.next().t - trr.first_frame.t
            trr.close()
            break

    # dt is sometimes noisy in the final digits (three digits is femtosecond step = enough)
    dt = np.around(dt, decimals=3)
    for n in needy_nodes:

        if (options.trr):
            # merge sampling trajectories
            trr_fns = sorted([
                fn for fn in os.listdir(n.dir)
                if re.match("[^#].+run\d+.trr", fn)
            ])
            cmd = ["trjcat", "-f"]
            cmd += trr_fns
            cmd += ["-o", "../../" + n.trr_fn, "-cat"]
            print("Calling: %s" % " ".join(cmd))
            check_call(cmd, cwd=n.dir)

        if (options.edr):
            # merge edr files
            # get list of edr-files
            edr_fnames = sorted([
                n.dir + "/" + fn for fn in os.listdir(n.dir)
                if re.match("[^#].+run\d+.edr", fn)
            ])
            assert (len(edr_fnames) == n.extensions_counter + 1)
            assert (len(edr_fnames) == n.extensions_max + 1)

            time_offset = n.sampling_length + dt

            for edr_fn in edr_fnames[1:]:
                # adapt edr starting times
                cmd = ["eneconv", "-f", edr_fn, "-o", edr_fn, "-settime"]
                print("Calling: " + (" ".join(cmd)))
                p = Popen(cmd, stdin=PIPE)
                p.communicate(input=(str(time_offset) + "\n"))
                assert (p.wait() == 0)

                time_offset += n.extensions_length + dt

            # concatenate edr files with adapted starting times
            cmd = ["eneconv", "-f"] + edr_fnames + ["-o", n.dir + "/ener.edr"]
            print("Calling: " + (" ".join(cmd)))
            p = Popen(cmd)
            retcode = p.wait()
            assert (retcode == 0)

    needy_nodes.unlock()
示例#45
0
def main():
    pool = Pool()
    for n in pool.where("isa_partition"):
        for cn in n.children.where("is_sampled"):
            print cn.trajectory
示例#46
0
def main():
    pool = Pool()
    for n in pool.where("isa_partition"):
        for cn in n.children.where("is_sampled"):
            print cn.trajectory
示例#47
0
def is_applicable():
	pool = Pool()
	return( len(pool) > 1 and len(pool.where("isa_partition and state in ('converged','not-converged','mdrun-failed')")) == len(pool.where("isa_partition")) )
示例#48
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	zgf_cleanup.main()
	
	print("Options:\n%s\n"%pformat(eval(str(options))))
	
	pool = Pool()
	parent = pool.root
	active_nodes = pool.where("isa_partition")
	
	assert(len(active_nodes) == len(active_nodes.multilock())) # make sure we lock ALL nodes

	if active_nodes.where("'weight_direct' not in obs"):
		sys.exit("Q-Matrix calculation not possible: Not all of the nodes have been reweighted.")

	node_weights = np.array([node.obs.weight_direct for node in active_nodes])
	
	print "### Generate bins: equidist ###" 
	result = q_equidist(parent, options.numnodes)
	chosen_idx=result['chosen_idx']
	frames_chosen=result['frames_chosen']
	theta=result['theta']
	chosen_idx.sort() # makes preview-trajectory easier to understand
	dimension=len(chosen_idx)

	print "chosen_idx"
	print chosen_idx

	print "### Generate bin weights ###"
	bin_weights=np.zeros(dimension)
	for (i,n) in enumerate(active_nodes):
		w_denom = np.sum(n.frameweights) 
		for t in range(len(n.trajectory)):
			diffs = (frames_chosen - n.trajectory.getframe(t)).norm()
			j = np.argmin(diffs)
			bin_weights[j] = bin_weights[j] + node_weights[i] * n.frameweights[t] / w_denom
			
	
	print "bin_weights"
	print bin_weights
	
	print "### Generate q_all (entries only for neighboring bins) ###" 
	q_all = np.empty((dimension, dimension), dtype=np.float)
	for i in range(dimension):
		sum_row = 0.0
		diffs = (frames_chosen - frames_chosen.getframe(i)).norm()
		print "diffs"
		print diffs
		for j in range(dimension):
			if (diffs[j] < 2.0 * theta) and (bin_weights[i] > 0.0):
				q_all[i,j] = np.sqrt(bin_weights[j]) / np.sqrt(bin_weights[i])
				sum_row = sum_row + q_all[i , j]
			else:
				q_all[i,j] = 0
		q_all[i, i] = q_all[i, i]- sum_row  
			
	print "Q_All"
	print q_all
	
	if options.export_matlab:
		savemat(pool.analysis_dir+"q_all.mat", {"q_all":q_all})
		
	active_nodes.unlock()
	zgf_cleanup.main()
示例#49
0
def main():
	options = options_desc.parse_args(sys.argv)[0]
	
	pool = Pool()

	if options.ignore_convergence:
		needy_nodes = pool.where("state in ('converged','not-converged')")
	else:
		needy_nodes = pool.where("state == 'converged'")

	assert(len(needy_nodes) == len(needy_nodes.multilock())) # make sure we lock ALL nodes

	for node in needy_nodes:
		
		if ( path.exists(node.dir+"/rerun_me.trr") and path.exists(node.dir+"/rerun_me.pdb") and path.exists(node.dir+"/rerun_me.top") and path.exists(node.dir+"/rerun_me.tpr") ):
			print("All four rerun files (rerun_me.*) already existing in " + node.dir + ".")
			print("Be sure you want to keep them!")
			continue
			
			
		# if "none", assume that sim is implicit or in vacuum. thus, trjconv not required. 
		if options.pbc_removal != "none":

			# desolvate trr
			if not( path.exists(node.dir+"/rerun_me.trr")):
				cmd = ["trjconv", "-f", node.trr_fn, "-o", node.dir+"/rerun_me.trr", "-s", node.tpr_fn, "-n", node.pool.ndx_fn, "-pbc", options.pbc_removal]			
				print("Calling: "+(" ".join(cmd)))
				p = Popen(cmd, stdin=PIPE)
				p.communicate(input=("MOI\n"))
				assert(p.wait() == 0)
			else:
				print("Rerun trajectory file (rerun_me.trr) already existing in " + node.dir + ".") 
				print("Be sure you want to keep it!")
				#sys.exit(0)
				#continue
	
			# desolvate pdb
			if not( path.exists(node.dir+"/rerun_me.pdb") ):
				cmd = ["trjconv", "-f", node.pdb_fn, "-o", node.dir+"/rerun_me.pdb", "-s", node.tpr_fn, "-n", node.pool.ndx_fn, "-pbc",	options.pbc_removal]			
				print("Calling: "+(" ".join(cmd)))
				p = Popen(cmd, stdin=PIPE)
				p.communicate(input=("MOI\n"))
				assert(p.wait() == 0)
	
			# desolvate topology
			infile = open(node.top_fn, "r").readlines()
			mol_section = False
			out_top = []
		
			for line in infile:
				if( re.match("\s*\[\s*(molecules)\s*\]\s*", line.lower()) ):
					# we are past the "molecules" section
					mol_section = True
				if(mol_section):
					# comment out lines that belong to solvent (SOL, CL, NA)... add more if necessary
					if( re.match("\s*(sol|cl|na|tsl|tcm|mth)\s*\d+", line.lower()) ):
						line = ";"+line
				out_top.append(line)
			outfile = open(node.dir+"/rerun_me.top","w").writelines(out_top)	
		
		else:
			if not( path.exists(node.dir+"/rerun_me.trr") ):
				symlink(node.name+".trr", node.dir+"/rerun_me.trr")
			else:
				print("Rerun trajectory file (rerun_me.trr) already existing in " + node.dir + ".") 
				print("Be sure you want to keep it!")
				#continue
			if not( path.exists(node.dir+"/rerun_me.pdb") ):
				symlink(node.name+"_conf.pdb", node.dir+"/rerun_me.pdb")
			if not( path.exists(node.dir+"/rerun_me.top") ):
				symlink(node.name+".top", node.dir+"/rerun_me.top")
		
	
		grompp2state = "rerun-able-"+node.state
	
		# get rid of old checkpoint file (it might mess up the rerun)
		if( path.exists(node.dir+"/state.cpt") ):
			remove(node.dir+"/state.cpt")
	
		#zgf_grompp.call_grompp(node, mdp_file=options.grompp, final_state=grompp2state)
		#TODO code borrowed from zgf_grompp
		#TODO make the original method fit for grompping reruns

		if not( path.exists(node.dir+"/rerun_me.trr") ):		
			cmd = ["grompp"]
			cmd += ["-f", "../../"+options.grompp]
			cmd += ["-n", "../../"+node.pool.ndx_fn]
			cmd += ["-c", "../../"+node.dir+"/rerun_me.pdb"]
			cmd += ["-p", "../../"+node.dir+"/rerun_me.top"]
			cmd += ["-o", "../../"+node.dir+"/rerun_me.tpr"]			
			print("Calling: %s"%" ".join(cmd))
			p = Popen(cmd, cwd=node.dir)
			retcode = p.wait()
			assert(retcode == 0) # grompp should never fail
		
		node.state = grompp2state
		node.save()
	
		node.unlock()
示例#50
0
def main():
    options = options_desc.parse_args(sys.argv)[0]

    pool = Pool()

    if options.ignore_convergence:
        needy_nodes = pool.where("state in ('converged','not-converged')")
    else:
        needy_nodes = pool.where("state == 'converged'")

    assert (len(needy_nodes) == len(needy_nodes.multilock())
            )  # make sure we lock ALL nodes

    for node in needy_nodes:

        if (path.exists(node.dir + "/rerun_me.trr")
                and path.exists(node.dir + "/rerun_me.pdb")
                and path.exists(node.dir + "/rerun_me.top")
                and path.exists(node.dir + "/rerun_me.tpr")):
            print("All four rerun files (rerun_me.*) already existing in " +
                  node.dir + ".")
            print("Be sure you want to keep them!")
            continue

        # if "none", assume that sim is implicit or in vacuum. thus, trjconv not required.
        if options.pbc_removal != "none":

            # desolvate trr
            if not (path.exists(node.dir + "/rerun_me.trr")):
                cmd = [
                    "trjconv", "-f", node.trr_fn, "-o",
                    node.dir + "/rerun_me.trr", "-s", node.tpr_fn, "-n",
                    node.pool.ndx_fn, "-pbc", options.pbc_removal
                ]
                print("Calling: " + (" ".join(cmd)))
                p = Popen(cmd, stdin=PIPE)
                p.communicate(input=("MOI\n"))
                assert (p.wait() == 0)
            else:
                print(
                    "Rerun trajectory file (rerun_me.trr) already existing in "
                    + node.dir + ".")
                print("Be sure you want to keep it!")
                #sys.exit(0)
                #continue

            # desolvate pdb
            if not (path.exists(node.dir + "/rerun_me.pdb")):
                cmd = [
                    "trjconv", "-f", node.pdb_fn, "-o",
                    node.dir + "/rerun_me.pdb", "-s", node.tpr_fn, "-n",
                    node.pool.ndx_fn, "-pbc", options.pbc_removal
                ]
                print("Calling: " + (" ".join(cmd)))
                p = Popen(cmd, stdin=PIPE)
                p.communicate(input=("MOI\n"))
                assert (p.wait() == 0)

            # desolvate topology
            infile = open(node.top_fn, "r").readlines()
            mol_section = False
            out_top = []

            for line in infile:
                if (re.match("\s*\[\s*(molecules)\s*\]\s*", line.lower())):
                    # we are past the "molecules" section
                    mol_section = True
                if (mol_section):
                    # comment out lines that belong to solvent (SOL, CL, NA)... add more if necessary
                    if (re.match("\s*(sol|cl|na|tsl|tcm|mth)\s*\d+",
                                 line.lower())):
                        line = ";" + line
                out_top.append(line)
            outfile = open(node.dir + "/rerun_me.top", "w").writelines(out_top)

        else:
            if not (path.exists(node.dir + "/rerun_me.trr")):
                symlink(node.name + ".trr", node.dir + "/rerun_me.trr")
            else:
                print(
                    "Rerun trajectory file (rerun_me.trr) already existing in "
                    + node.dir + ".")
                print("Be sure you want to keep it!")
                #continue
            if not (path.exists(node.dir + "/rerun_me.pdb")):
                symlink(node.name + "_conf.pdb", node.dir + "/rerun_me.pdb")
            if not (path.exists(node.dir + "/rerun_me.top")):
                symlink(node.name + ".top", node.dir + "/rerun_me.top")

        grompp2state = "rerun-able-" + node.state

        # get rid of old checkpoint file (it might mess up the rerun)
        if (path.exists(node.dir + "/state.cpt")):
            remove(node.dir + "/state.cpt")

        #zgf_grompp.call_grompp(node, mdp_file=options.grompp, final_state=grompp2state)
        #TODO code borrowed from zgf_grompp
        #TODO make the original method fit for grompping reruns

        if not (path.exists(node.dir + "/rerun_me.trr")):
            cmd = ["grompp"]
            cmd += ["-f", "../../" + options.grompp]
            cmd += ["-n", "../../" + node.pool.ndx_fn]
            cmd += ["-c", "../../" + node.dir + "/rerun_me.pdb"]
            cmd += ["-p", "../../" + node.dir + "/rerun_me.top"]
            cmd += ["-o", "../../" + node.dir + "/rerun_me.tpr"]
            print("Calling: %s" % " ".join(cmd))
            p = Popen(cmd, cwd=node.dir)
            retcode = p.wait()
            assert (retcode == 0)  # grompp should never fail

        node.state = grompp2state
        node.save()

        node.unlock()
示例#51
0
def is_applicable():
    pool = Pool()
    return (len(pool.where("state == 'created'")) > 0)
示例#52
0
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()
示例#53
0
def is_applicable():
    pool = Pool()
    return (len(
        pool.where("state in ('converged', 'not-converged', 'refined')")) > 1)