src/setup.py
def import_files_mpi(sim_dir, file_names, param, comm, size=1, rank=0, verbosity=True):
	"""
	import_files(sim_dir, file_names, param)

	Imports existing or creates new simulation files listed in file_names 

	Parameters
	----------

	sim_dir:  str
		Directory in which simulation files are to be saved

	file_names:  list (str)
		List of simulation and analysis files names

	param:  dict
		Dictionary of simulation and analysis parameters

	Returns
	-------

	pos:  array_like (float); shape=(n_bead, n_dim)
		Positions of n_bead beads in n_dim

	vel: array_like, dtype=float
		Velocity of each bead in all collagen fibrils

	cell_dim:  array_like (float); shape=(n_dim)
		Simulation cell dimensions in n_dim dimensions

	param:  dict
		Dictionary of simulation and analysis parameters
	"""

	from mpi4py import MPI
	from simulation_mpi import equilibrate_temperature_mpi, equilibrate_density_mpi

	if os.path.exists(sim_dir + file_names['restart_file_name'] + '.npy'):
		if rank == 0: 
			if verbosity: print(" Loading restart file {}.npy".format(sim_dir + file_names['restart_file_name']))
			restart = ut.load_npy(sim_dir + file_names['restart_file_name'])
		else: restart = None
		restart = comm.bcast(restart, root=0)

		pos = restart[0]
		vel = restart[1]
		cell_dim = pos[-1]
		pos = pos[:-1]

	elif os.path.exists(sim_dir + file_names['pos_file_name'] + '.npy'):
		if rank == 0:
			if verbosity: print(" Loading position file {}.npy".format(sim_dir + file_names['pos_file_name']))
			pos = ut.load_npy(sim_dir + file_names['pos_file_name'])
		else: pos = None
		pos = comm.bcast(pos, root=0)
		
		cell_dim = pos[-1]
		pos = pos[:-1]

		pos, vel = equilibrate_temperature_mpi(sim_dir, pos, cell_dim, param, comm, size, rank)

	else:
		file_names['pos_file_name'] = ut.check_file_name(file_names['pos_file_name'], file_type='pos') + '_pos'

		if rank == 0: 
			if verbosity: print(" Creating input pos file {}{}.npy".format(sim_dir, file_names['pos_file_name']))
			pos, cell_dim, param = create_pos_array(param)

			#param['l_conv'] = 1. / param['vdw_sigma']

			keys = ['bond_matrix', 'angle_array', 'vdw_matrix']#, 'l_conv']
			for key in keys: ut.update_param_file(sim_dir + file_names['param_file_name'], key, param[key])

			if verbosity: print(" Saving input pos file {}{}.npy".format(sim_dir, file_names['pos_file_name']))
			ut.save_npy(sim_dir + file_names['pos_file_name'], np.vstack((pos, cell_dim)))
		else:
			pos = None
			cell_dim = None

		pos = comm.bcast(pos, root=0)
		cell_dim = comm.bcast(cell_dim, root=0)
		param = comm.bcast(param, root=0)

		pos, vel = equilibrate_temperature_mpi(sim_dir, pos, cell_dim, param, comm, size, rank)
		pos, vel, cell_dim = equilibrate_density_mpi(pos, vel, cell_dim, param, comm, size, rank)

		if rank == 0: 
			if verbosity: print(" Saving restart file {}".format(file_names['restart_file_name']))
			ut.save_npy(sim_dir + file_names['restart_file_name'], (np.vstack((pos, cell_dim)), vel))

	return pos, vel, cell_dim, param

	import_files(sim_dir, file_names, param)

	Imports existing or creates new simulation files listed in file_names 

	Parameters
	----------

	sim_dir:  str
		Directory in which simulation files are to be saved

	file_names:  list (str)
		List of simulation and analysis files names

	param:  dict
		Dictionary of simulation and analysis parameters

	Returns
	-------

	pos:  array_like (float); shape=(n_bead, n_dim)
		Positions of n_bead beads in n_dim

	vel: array_like, dtype=float
		Velocity of each bead in all collagen fibrils

	cell_dim:  array_like (float); shape=(n_dim)
		Simulation cell dimensions in n_dim dimensions

	param:  dict
		Dictionary of simulation and analysis parameters
	


Parameters

str
Directory in which simulation files are to be saved

list (str)
List of simulation and analysis files names

dict
Dictionary of simulation and analysis parameters

Returns



array_like, dtype=float
Velocity of each bead in all collagen fibrils



dict
Dictionary of simulation and analysis parameters
Parameters str Directory in which simulation files are to be saved list ( str ) List of simulation and analysis files names dict Dictionary of simulation and analysis parameters Returns array_like dtype = float Velocity of each bead in all collagen fibrils dict Dictionary of simulation and analysis parameters
def import_files_mpi(sim_dir, file_names, param, comm, size=1, rank=0, verbosity=True):
	from mpi4py import MPI
	from simulation_mpi import equilibrate_temperature_mpi, equilibrate_density_mpi
	if os.path.exists(sim_dir + file_names['restart_file_name'] + '.npy'):
		if rank == 0: 
			if verbosity: print(" Loading restart file {}.npy".format(sim_dir + file_names['restart_file_name']))
			restart = ut.load_npy(sim_dir + file_names['restart_file_name'])
		else: restart = None
		restart = comm.bcast(restart, root=0)
		pos = restart[0]
		vel = restart[1]
		cell_dim = pos[-1]
		pos = pos[:-1]
	elif os.path.exists(sim_dir + file_names['pos_file_name'] + '.npy'):
		if rank == 0:
			if verbosity: print(" Loading position file {}.npy".format(sim_dir + file_names['pos_file_name']))
			pos = ut.load_npy(sim_dir + file_names['pos_file_name'])
		else: pos = None
		pos = comm.bcast(pos, root=0)
		cell_dim = pos[-1]
		pos = pos[:-1]
		pos, vel = equilibrate_temperature_mpi(sim_dir, pos, cell_dim, param, comm, size, rank)
	else:
		file_names['pos_file_name'] = ut.check_file_name(file_names['pos_file_name'], file_type='pos') + '_pos'
		if rank == 0: 
			if verbosity: print(" Creating input pos file {}{}.npy".format(sim_dir, file_names['pos_file_name']))
			pos, cell_dim, param = create_pos_array(param)
			keys = ['bond_matrix', 'angle_array', 'vdw_matrix']
			for key in keys: ut.update_param_file(sim_dir + file_names['param_file_name'], key, param[key])
			if verbosity: print(" Saving input pos file {}{}.npy".format(sim_dir, file_names['pos_file_name']))
			ut.save_npy(sim_dir + file_names['pos_file_name'], np.vstack((pos, cell_dim)))
		else:
			pos = None
			cell_dim = None
		pos = comm.bcast(pos, root=0)
		cell_dim = comm.bcast(cell_dim, root=0)
		param = comm.bcast(param, root=0)
		pos, vel = equilibrate_temperature_mpi(sim_dir, pos, cell_dim, param, comm, size, rank)
		pos, vel, cell_dim = equilibrate_density_mpi(pos, vel, cell_dim, param, comm, size, rank)
		if rank == 0: 
			if verbosity: print(" Saving restart file {}".format(file_names['restart_file_name']))
			ut.save_npy(sim_dir + file_names['restart_file_name'], (np.vstack((pos, cell_dim)), vel))
	return pos, vel, cell_dim, param
def import_files_mpi ( sim_dir , file_names , param , comm , size = 1 , rank = 0 , verbosity = True ) : from mpi4py import MPI from simulation_mpi import equilibrate_temperature_mpi , equilibrate_density_mpi if os . path . exists ( sim_dir + file_names [ 'restart_file_name' ] + '.npy' ) : if rank == 0 : if verbosity : print ( " Loading restart file {}.npy" . format ( sim_dir + file_names [ 'restart_file_name' ] ) ) restart = ut . load_npy ( sim_dir + file_names [ 'restart_file_name' ] ) else : restart = None restart = comm . bcast ( restart , root = 0 ) pos = restart [ 0 ] vel = restart [ 1 ] cell_dim = pos [ - 1 ] pos = pos [ : - 1 ] elif os . path . exists ( sim_dir + file_names [ 'pos_file_name' ] + '.npy' ) : if rank == 0 : if verbosity : print ( " Loading position file {}.npy" . format ( sim_dir + file_names [ 'pos_file_name' ] ) ) pos = ut . load_npy ( sim_dir + file_names [ 'pos_file_name' ] ) else : pos = None pos = comm . bcast ( pos , root = 0 ) cell_dim = pos [ - 1 ] pos = pos [ : - 1 ] pos , vel = equilibrate_temperature_mpi ( sim_dir , pos , cell_dim , param , comm , size , rank ) else : file_names [ 'pos_file_name' ] = ut . check_file_name ( file_names [ 'pos_file_name' ] , file_type = 'pos' ) + '_pos' if rank == 0 : if verbosity : print ( " Creating input pos file {}{}.npy" . format ( sim_dir , file_names [ 'pos_file_name' ] ) ) pos , cell_dim , param = create_pos_array ( param ) keys = [ 'bond_matrix' , 'angle_array' , 'vdw_matrix' ] for key in keys : ut . update_param_file ( sim_dir + file_names [ 'param_file_name' ] , key , param [ key ] ) if verbosity : print ( " Saving input pos file {}{}.npy" . format ( sim_dir , file_names [ 'pos_file_name' ] ) ) ut . save_npy ( sim_dir + file_names [ 'pos_file_name' ] , np . vstack ( ( pos , cell_dim ) ) ) else : pos = None cell_dim = None pos = comm . bcast ( pos , root = 0 ) cell_dim = comm . bcast ( cell_dim , root = 0 ) param = comm . bcast ( param , root = 0 ) pos , vel = equilibrate_temperature_mpi ( sim_dir , pos , cell_dim , param , comm , size , rank ) pos , vel , cell_dim = equilibrate_density_mpi ( pos , vel , cell_dim , param , comm , size , rank ) if rank == 0 : if verbosity : print ( " Saving restart file {}" . format ( file_names [ 'restart_file_name' ] ) ) ut . save_npy ( sim_dir + file_names [ 'restart_file_name' ] , ( np . vstack ( ( pos , cell_dim ) ) , vel ) ) return pos , vel , cell_dim , param
import_files(sim_dir, file_names, param)
Imports existing or creates new simulation files listed in file_names
import_files ( sim_dir file_names param ) Imports existing or creates new simulation files listed in file_names
"""
	import_files(sim_dir, file_names, param)

	Imports existing or creates new simulation files listed in file_names 

	Parameters
	----------

	sim_dir:  str
		Directory in which simulation files are to be saved

	file_names:  list (str)
		List of simulation and analysis files names

	param:  dict
		Dictionary of simulation and analysis parameters

	Returns
	-------

	pos:  array_like (float); shape=(n_bead, n_dim)
		Positions of n_bead beads in n_dim

	vel: array_like, dtype=float
		Velocity of each bead in all collagen fibrils

	cell_dim:  array_like (float); shape=(n_dim)
		Simulation cell dimensions in n_dim dimensions

	param:  dict
		Dictionary of simulation and analysis parameters
	""" #param['l_conv'] = 1. / param['vdw_sigma'] #, 'l_conv']
sim_dir
file_names
param
comm
size
rank
verbosity