print("{:40}{:15d}  ".format('Size of each ring polymer', p))
print("{:40}{:15d}  ".format('Number of blocks', nblock))
print("{:40}{:15d}  ".format('Number of steps per block', nstep))
print("{:40}{:15.6f}".format('Temperature', temperature))
print("{:40}{:15.6f}".format('Potential cutoff distance', r_cut))
print("{:40}{:15.6f}".format('Maximum displacement', dr_max))
print("{:40}{:15.6f}".format('Maximum COM displacement', dc_max))
print("{:40}{:15.6f}".format('de Boer length', deboer))
assert p > 1 and p < 100, 'p must lie between 2 and 99'
k_spring = p * (temperature / deboer)**2
print("{:40}{:15.6f}".format('Quantum spring constant', k_spring))

# Read in initial configuration
# Read each polymer index from a unique file; we assume that n and box are all the same!
n, box, r = read_cnf_atoms(
    cnf_prefix + '00.' +
    inp_tag)  #  Read first LJ configuration to get basic parameters n and box
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box length', box))
print("{:40}{:15.6f}".format('Density', n / box**3))
r = np.empty((p, n, 3), dtype=np.float_)
for k in range(p):
    n, box, r[k, :, :] = read_cnf_atoms(cnf_prefix + str(k).zfill(2) + '.' +
                                        inp_tag)
r = r / box  # Convert positions to box units
r = r - np.rint(r)  # Periodic boundaries

# Calculate classical LJ and quantum spring potential energies & check overlap
total = potential(box, r_cut, r)
assert not total.ovr, 'Overlap in initial configuration'
total_spr = spring(box, k_spring, r)
Example #2
0
        print('Warning', key, 'not in ', list(defaults.keys()))

# Set parameters to input values or defaults
nblock = nml["nblock"] if "nblock" in nml else defaults["nblock"]
nstep = nml["nstep"] if "nstep" in nml else defaults["nstep"]
dt = nml["dt"] if "dt" in nml else defaults["dt"]

introduction()

# Write out parameters
print("{:40}{:15d}  ".format('Number of blocks', nblock))
print("{:40}{:15d}  ".format('Number of steps per block', nstep))
print("{:40}{:15.6f}".format('Time step', dt))

# Read in initial configuration
n, box, r, v = read_cnf_atoms(cnf_prefix + inp_tag, with_v=True)
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box length (sigma units)', box))
print("{:40}{:15.6f}".format('Density', n / box**3))
r = r / box  # Convert positions to box units
r = r - np.rint(r)  # Periodic boundaries
vcm = np.sum(v, axis=0) / n  # Centre-of mass velocity
v = v - vcm  # Set COM velocity to zero
kin = 0.5 * np.sum(v**2)
temp_kinet = 2.0 * kin / (3 * (n - 1))
v = v / np.sqrt(temp_kinet)  # We fix the temperature to be 1.0
kin = 0.5 * np.sum(v**2)
temp_kinet = 2.0 * kin / (3 * (n - 1))
print("{:40}{:15.6f}".format('Temperature', temp_kinet))

# Initial overlap check
elif "atom" in molecules:
    molecule_option = atom
    print('Atoms')
else:
    molecule_option = chain
    print('Atoms in a chain')

assert velocities or np.fabs(delta_kin) < tol, 'No kinetic energy change possible'
assert molecule_option != chain or np.fabs(delta_rho) < tol, 'No density change possible'

atomic = molecule_option==atom or molecule_option==chain
quaternions = molecule_option==nonlinear

if atomic:
    if velocities:
        n, box, r, v = read_cnf_atoms ( filename, with_v=True )
    else:
        n, box, r = read_cnf_atoms ( filename, with_v=False )
else:
    if velocities:
        n, box, r, e, v, w = read_cnf_mols ( filename, with_v=True, quaternions=quaternions )
    else:
        n, box, r, e = read_cnf_mols ( filename, with_v=False, quaternions=quaternions )

if molecule_option == chain:
    print("{:40}{:15.6f}".format('Molecular bond length',box) ) # box plays role of bond
else:
    rho = n / box**3
    print("{:40}{:15.6f}".format('Simulation box length',box) )
    print("{:40}{:15.6f}".format('Density',rho) )
        
# Set default values, check keys and typecheck values
defaults = {"r_cl": 1.5}
for key, val in nml.items():
    if key in defaults:
        assert type(val) == type(defaults[key]), key + " has the wrong type"
    else:
        print('Warning', key, 'not in ', list(defaults.keys()))

# Set parameters to input values or defaults
r_cl = nml["r_cl"] if "r_cl" in nml else defaults["r_cl"]

# Write out parameters
print("{:40}{:15.6f}".format('Cluster separation distance', r_cl))

# Read in configuration
n, box, r = read_cnf_atoms('cluster.inp')
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box (in sigma units)', box))

r = r - np.rint(r / box) * box  # Apply periodic boundaries
r_cl_sq = r_cl**2  # Used in in_range function
my_list = np.arange(n, dtype=np.int_)  # Set up the list

for i in range(n - 1):  # Begin outer loop
    if i == my_list[i]:
        j = i
        while True:  # Begin inner loop
            for k in range(i + 1, n):  # Begin innermost loop
                if my_list[k] == k:
                    if in_range(j, k):
                        my_list[k], my_list[j] = my_list[j], my_list[
introduction()
np.random.seed()

# Write out parameters
print("{:40}{:15d}  ".format('Number of blocks', nblock))
print("{:40}{:15d}  ".format('Number of steps per block', nstep))
print("{:40}{:15.6f}".format('Specified temperature', temperature))
print("{:40}{:15.6f}".format('Specified activity', activity))
print("{:40}{:15.6f}".format('Probability of move', prob_move))
print("{:40}{:15.6f}".format('Probability of create/destroy', prob_create))
print("{:40}{:15.6f}".format('Potential cutoff distance', r_cut))
print("{:40}{:15.6f}".format('Maximum displacement', dr_max))

# Read in initial configuration
n, box, r = read_cnf_atoms(cnf_prefix + inp_tag)
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box length', box))
print("{:40}{:15.6f}".format('Density', n / box**3))
r = r / box  # Convert positions to box units
r = r - np.rint(r)  # Periodic boundaries

# Initial energy and overlap check
total = potential(box, r_cut, r)
assert not total.ovr, 'Overlap in initial configuration'

# Initialize arrays for averaging and write column headings
m_ratio = 0.0
c_ratio = 0.0
d_ratio = 0.0
run_begin(calc_variables())
Example #6
0
dv_max = nml["dv_max"] if "dv_max" in nml else defaults["dv_max"]

introduction()
np.random.seed()

# Write out parameters
print("{:40}{:15d}  ".format('Number of blocks', nblock))
print("{:40}{:15d}  ".format('Number of steps per block', nstep))
print("{:40}{:15d}  ".format('Swap attempts per step', nswap))
print("{:40}{:15.6f}".format('Specified temperature', temperature))
print("{:40}{:15.6f}".format('Potential cutoff distance', r_cut))
print("{:40}{:15.6f}".format('Maximum displacement', dr_max))
print("{:40}{:15.6f}".format('Maximum volume change', dv_max))

# Read in initial configurations
n1, box1, r1 = read_cnf_atoms(cnf1_prefix + inp_tag)
n2, box2, r2 = read_cnf_atoms(cnf2_prefix + inp_tag)
print("{:40}{:15d}{:15d}    ".format('Number of particles', n1, n2))
print("{:40}{:15.6f}{:15.6f}".format('Simulation box length', box1, box2))
print("{:40}{:15.6f}{:15.6f}".format('Density', n1 / box1**3, n2 / box2**3))
r1 = r1 / box1  # Convert positions to box units
r2 = r2 / box2  # Convert positions to box units
r1 = r1 - np.rint(r1)  # Periodic boundaries
r2 = r2 - np.rint(r2)  # Periodic boundaries

# Initial energy and overlap check
total1 = potential(box1, r_cut, r1)
assert not total1.ovr, 'Overlap in initial configuration 1'
total2 = potential(box2, r_cut, r2)
assert not total2.ovr, 'Overlap in initial configuration 2'
Example #7
0
        assert type(val) == type(defaults[key]), key + " has the wrong type"
    else:
        print('Warning', key, 'not in ', list(defaults.keys()))

# Set parameters to input values or defaults
dr = nml["dr"] if "dr" in nml else defaults["dr"]

# Write out parameters
print("{:40}{:15.6f}".format('g(r) spacing dr', dr))

# Read in configuration
cnf_prefix = 'cnf.'
if not os.path.isfile(cnf_prefix + '000'):
    print(cnf_prefix + '000 does not exist')
    sys.exit()
n, box, r = read_cnf_atoms(cnf_prefix + '000')
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box (in sigma units)', box))
dr = dr / box  # Convert to box=1 units
nk = math.floor(0.5 / dr)  # Accumulate out to half box length
r_max = nk * dr  # Actual r_max (box=1 units)
print("{:40}{:15d}  ".format('Number of bins', nk))
print("{:40}{:15.6f}".format('Maximum r/box', r_max))

h = np.zeros(nk, dtype=np.int_)  # Histogram bins initialized to zero
nstep = 0  # Counts configurations

while True:  # Loop until configurations or naming scheme exhausted
    if nstep >= 1000:
        break
    sav_tag = str(nstep).zfill(3)
    else:
        print('Warning', key, 'not in ', list(defaults.keys()))
    
# Set parameters to input values or defaults
kappa = nml["kappa"] if "kappa" in nml else defaults["kappa"]
nk    = nml["nk"]    if "nk"    in nml else defaults["nk"]
nbox  = nml["nbox"]  if "nbox"  in nml else defaults["nbox"]

# Write out parameters
print ( "{:40}{:15.6f}".format('kappa*box',                           kappa) )
print ( "{:40}{:15d}"  .format('Wave-vector limit in each direction', nk)    )
print ( "{:40}{:15d}"  .format('Brute force box limit',               nbox)  )
nbox_sq = nbox**2

# Read in configuration
n, box, r = read_cnf_atoms('cnf.inp')
print("{:40}{:15d}  ".format('Number of particles', n))
print("{:40}{:15.6f}".format('Box (in sigma units)',box))
r = r / box        # Work throughout in unit box
r = r - np.rint(r) # Apply periodic boundaries
assert n%2 == 0, 'Error, we require even N for charge balance'
q = np.empty(n,dtype=np.float_)
q[::2] = 1.0
q[1::2] = -1.0
print ( "{:40}{:15.6f}".format('Net charge', np.sum(q)) )

# Compute potential energy by Ewald method
pot_r  = pot_r_ewald ( r, q, kappa )                # Real-space term involving screened Coulomb potential
pot_k  = pot_k_ewald ( nk, r, q, kappa )            # Reciprocal space term
dipole = np.sum ( q[:,np.newaxis]*r[:,:], axis=0 )  # Calculate overall box dipole
pot_s  = ( 2.0*np.pi / 3.0 ) * np.sum ( dipole**2 ) # Surface term