示例#1
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()
示例#2
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()
示例#3
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()
示例#4
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()
示例#5
0
def process(node, options):
	
	cmd1 = ["mdrun"]
	
	if(node.state == "em-mdrun-able"):
		cmd1 += ["-s", "../../"+node.tpr_fn]
		cmd1 += ["-c", "../../"+node.pdb_fn]
		cmd1 += ["-o", "../../"+node.dir+"/em.trr"]
		cmd1 += ["-e", "../../"+node.dir+"/em.edr"]
		cmd1 += ["-g", "../../"+node.dir+"/em.log"]
	elif(node.state in ('rerun-able-converged','rerun-able-not-converged')):
		cmd1 += ["-s", "../../"+node.dir+"/rerun_me.tpr"]
		cmd1 += ["-rerun", "../../"+node.dir+"/rerun_me.trr"]
		cmd1 += ["-o", "../../"+node.dir+"/rerun.trr"]
		cmd1 += ["-e", "../../"+node.dir+"/rerun.edr"]
		cmd1 += ["-g", "../../"+node.dir+"/rerun.log"]
	else:
		cmd1 += ["-s", "../../"+node.tpr_fn]
		cmd1 += ["-o", "../../"+node.trr_fn]
		cmd1 += ["-c", "../../"+node.dir+"/outfile.pdb"]

	cmd1 += ["-append", "-cpi", "state.cpt"] # continue previouly state, if exists
	if(options.npme != -1):
		cmd1 += ["-npme", str(options.npme)]
	if(options.nt != 0):
		cmd1 += ["-nt", str(options.nt)]
	if(options.reprod):
		cmd1 += ["-reprod"]
	if(options.pd):
		cmd1 += ["-pd"]
	
	# do parallel job if preferred
	if(not options.seq):
		
		if(call(["which","mdrun_mpi"])==0):
			cmd1[0] = "mdrun_mpi"
			if(call(["which","mpiexec"])==0):
				cmd1 = ["mpiexec", "-np", str(options.np)] + cmd1
		
		if(not options.seq and str(options.pbs) == "mpiexec" and call(["which","mpiexec"])==0):
			cmd1 = ["mpiexec", "-np", str(options.np)] + cmd1


		if(not options.seq and str(options.pbs) == "aprun"):
				cmd1 = ["aprun", "-n", str(options.np)] + cmd1
				
	
	## use mpiexec and mdrun_mpi if available
	#if(not options.seq and call(["which","aprun"])==0):
	#	if(call(["which","mdrun_mpi"])==0):
	#		cmd1[0] = "mdrun_mpi"
	#	cmd1 = ["aprun", "-n", str(options.np)] + cmd1
		
	#http://stackoverflow.com/questions/4554767/terminating-subprocess-in-python
	#alternative
	#p = Popen(...)
	#pp = psutil.Process(p.pid)
	#for child in pp.get_children():
	#	child.send_signal(signal.SIGINT)
	
	#ensure, that childprocess dies when parent dies. Alternative: write own signal-handler e.g for atexit-module
	#http://stackoverflow.com/questions/1884941/killing-the-child-processes-with-the-parent-process
	implant_bomb = None
	try:
		import ctypes
		libc = ctypes.CDLL('libc.so.6')
		PR_SET_PDEATHSIG = 1; TERM = 15
		implant_bomb = lambda: libc.prctl(PR_SET_PDEATHSIG, TERM)
	except:
		warn("Child process might live on when parent gets terminated (feature requires python 2.6).")
	
	print("Calling: %s"%" ".join(cmd1))
	check_call(cmd1, cwd=node.dir, preexec_fn=implant_bomb)

	# if we were just minimizing, we go back to grompp-able now
	if(node.state == "em-mdrun-able"):
		node.state = "grompp-able"
		return

	# if we were just rerunnning, we go back to original state now
	if(node.state in ('rerun-able-converged','rerun-able-not-converged')):
		node.state = node.state.rsplit("rerun-able-", 1)[1]
		return

	if(node.has_restraints and not options.multistart):
		# check for convergence
		converged = conv_check_gelman_rubin(node)
	else:
		# stow away sampling data
		converged = False
		os.remove(node.dir+"/state.cpt")
		for fn in [node.dir+"/outfile.pdb",node.trr_fn, node.dir+"/ener.edr", node.dir+"/md.log"]:
			archive_file(fn, node.extensions_counter)

	# check if user wants to delete files except pdb
	try:
		if (node.save_mode == "pdb"):
			# delete all files except pdb and start files
			for fn in os.listdir(node.dir):
				if(re.match(".+.pdb",fn)==None
				and re.match("[^#].+.mdp",fn)==None
				and re.match(".+.txt",fn)==None
				and re.match("[^#].+.tpr",fn)==None
				and re.match(".+.top",fn)==None
				and fn!="lock"):
					os.remove(node.dir+"/"+str(fn))
	except AttributeError:
		pass
	
	# decide what to do next
	if(converged):
		node.state = "converged"
	elif(node.extensions_counter >= node.extensions_max):
		if(node.has_restraints and not options.multistart):
			node.state = "not-converged"
		else:
			# if user wants to keep everthing we at merge trajectorie and edr files
			# and delete backups
			try:			
				if (node.save_mode == "complete"):
					# merge sampling trajectories
					trr_fns = sorted([ fn for fn in os.listdir(node.dir) if re.match("[^#].+run\d+.trr", fn) ])
					cmd2 = ["trjcat", "-f"]
					cmd2 += trr_fns
					cmd2 += ["-o", "../../"+node.trr_fn, "-cat"]
					print("Calling: %s"%" ".join(cmd2))
					check_call(cmd2, cwd=node.dir)
					# merge edr files
					get_merged_edr(node)
					# delete backups, assuming each backup file starts with '#'
					for fn in os.listdir(node.dir):
						if(re.match("#.+",fn)):					
							os.remove(node.dir+"/"+str(fn))
			except AttributeError:
				pass
			
			# in either case, save as ready node
			node.state = "ready"
			

	else:
		node.extensions_counter += 1
		node.state = "mdrun-able" # actually it should still be in this state
	
		if(node.has_restraints and not options.multistart):
			cmd0 = ["tpbconv", "-s", node.tpr_fn, "-o", node.tpr_fn, "-extend", str(node.extensions_length)]
			print("Calling: %s"%" ".join(cmd0))
			check_call(cmd0) # tell Gromacs to extend the tpr file for another round
		else:
			node.state = "grompp-able"
			zgf_grompp.call_grompp(node) # re-grompp to obtain new random impulse