def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ from averages_module import VariableType import numpy as np import math # Preliminary calculations (m_ratio, v_ratio, box are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratios m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) v_r = VariableType(nam='Volume ratio', val=v_ratio, instant=False) # Density density = VariableType(nam='Density', val=rho) # Collect together into a list for averaging return [m_r, v_r, density]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ from averages_module import VariableType # Preliminary calculations kin = 0.5 * p * temperature # Kinetic energy for P-bead system # Move ratio m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) # Classical potential energy pe_cl = VariableType(nam='PE classical', val=pot_cl) # Quantum potential energy pe_qu = VariableType(nam='PE quantum', val=pot_qu) # Energy energy = VariableType(nam='Energy', val=kin + pot_cl - pot_qu) # Collect together into a list for averaging return [m_r, pe_cl, pe_qu, energy]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program.""" import numpy as np from averages_module import VariableType # Preliminary calculations vol = box**3 # Volume rho = n / vol # Density # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # We average over the time step coll_rate = VariableType(nam='Collision rate', val=2.0 * col_sum / dt / n, instant=False) # ideal + collisional virial / volume averaged over the time step p_coll = VariableType(nam='P', val=rho * temp_kinet + vir_sum / dt / vol, instant=False) # Collect together into a list for averaging return [coll_rate, p_coll]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ from averages_module import VariableType import numpy as np import math from mc_hs_module import n_overlap # Preliminary calculations (m_ratio, eps_box, box are taken from the calling program) vir = n_overlap(box / (1.0 + eps_box), r) / (3.0 * eps_box) # Virial vol = box**3 # Volume rho = n / vol # Density # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratio m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) # Pressure in units kT/sigma**3 # Ideal gas contribution plus total virial divided by V p_f = VariableType(nam='P', val=rho + vir / vol) # Collect together into a list for averaging return [m_r, p_f]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ import numpy as np import math from averages_module import msd, cke, VariableType # Preliminary calculations kin = 0.5 * np.sum(v**2) rcm = np.sum(r, axis=0) / n # Centre of mass rsq = np.sum((r - rcm)**2) / n # Mean-squared distance from CM eng = kin + total.pot # Total energy # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Internal energy per atom # Total KE plus total LJ nonbonded energy divided by N e_f = VariableType(nam='E/N', val=eng / n) # Kinetic temperature # Remove 6 degrees of freedom for conserved linear and angular momentum # and also (n-1) degrees of freedom for the bond constraints t_k = VariableType(nam='T kinetic', val=2.0 * kin / (3 * n - (n - 1) - 6)) # Radius of gyration r_g = VariableType(nam='Rg', val=math.sqrt(rsq)) # MSD of kinetic energy, intensive # Use special method to convert to Cv/N c_f = VariableType(nam='Cv/N', val=kin / math.sqrt(n), method=cke, instant=False) # Mean-squared deviation of conserved energy per atom conserved_msd = VariableType(nam='Conserved MSD', val=eng / n, method=msd, e_format=True, instant=False) # Collect together for averaging return [e_f, t_k, r_g, c_f, conserved_msd]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ import numpy as np import math from averages_module import msd, VariableType from mc_chain_lj_module import potential, spring_pot, PotentialType # Preliminary calculations total = potential(r) # Nonbonded potential with overlap flag assert not total.ovr, 'Overlap in configuration' spr = spring_pot(bond, k_spring, r) # Total spring potential energy rcm = np.sum(r, axis=0) / n # Centre of mass rsq = np.sum((r - rcm)**2) / n # Mean-squared distance from CM # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratio m_r = VariableType(nam='Regrow ratio', val=m_ratio, instant=False) # Total potential energy per atom (excess, without ideal gas contribution) # Total PE of bond springs plus total LJ PE (not cut, nor shifted) divided by N e_x = VariableType(nam='PE/N', val=(spr + total.pot) / n) # Radius of gyration r_g = VariableType(nam='Rg', val=np.sqrt(rsq)) # Heat Capacity per atom (excess, without ideal gas contribution) # MSD of PE / (sqrt(N)*T) # Total PE of bond springs plus total LJ PE (not cut, nor shifted), divided by T c_x = VariableType(nam='Cv(ex)/N', val=(spr + total.pot) / (np.sqrt(n) * temperature), method=msd, instant=False) # Collect together into a list for averaging return [m_r, e_x, r_g, c_x]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ # In this example we simulate using the shifted-force potential only # The values of < p_sf >, < e_sf > and density should be consistent (for this potential) # There are no long-range or delta corrections from averages_module import VariableType # Preliminary calculations vol = box**3 # Volume rho = n / vol # Density # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratio m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) # Internal energy per molecule (shifted-force potential) # Ideal gas contribution (assuming nonlinear molecules) plus total PE divided by N e_sf = VariableType(nam='E/N shifted force', val=3.0 * temperature + total.pot / n) # Pressure (shifted-force potential) # Ideal gas contribution plus total virial divided by V p_sf = VariableType(nam='P shifted force', val=rho * temperature + total.vir / vol) # Collect together into a list for averaging return [m_r, e_sf, p_sf]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ import numpy as np from averages_module import VariableType # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratios r_r = VariableType(nam='Regrow ratio', val=r_ratio, instant=False) c_r = VariableType(nam='Crank ratio', val=c_ratio, instant=False) p_r = VariableType(nam='Pivot ratio', val=p_ratio, instant=False) # Collect together into a list for averaging return [r_r, c_r, p_r]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ import numpy as np from averages_module import msd, VariableType # Preliminary calculations rcm = np.sum(r, axis=0) / n # Centre of mass rsq = np.sum((r - rcm)**2) / n # Mean-squared distance from CM # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratios r_r = VariableType(nam='Regrow ratio', val=r_ratio, instant=False) c_r = VariableType(nam='Crank ratio', val=c_ratio, instant=False) p_r = VariableType(nam='Pivot ratio', val=p_ratio, instant=False) # Total potential energy per atom # PE=negative of the number of square-well contacts divided by N e_x = VariableType(nam='PE/N', val=-q / n) # Radius of gyration r_g = VariableType(nam='Rg', val=np.sqrt(rsq)) # Heat Capacity per atom (excess, without ideal gas contribution, extensive) # MSD of PE / (sqrt(N)*T) # PE==negative of the number of square-well contacts c_x = VariableType(nam='Cv(ex)/N', val=-q / (np.sqrt(n) * temperature), method=msd, instant=False) # Collect together into a list for averaging return [r_r, c_r, p_r, e_x, r_g, c_x]
def calc_variables ( ): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ from averages_module import msd, VariableType from lrc_module import potential_lrc, pressure_lrc import numpy as np import math # Preliminary calculations (n,r,v,f,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density kin = 0.5*np.sum(v**2) # Kinetic energy fsq = np.sum ( f**2 ) # Total squared force ext = np.sum(0.5*p_eta**2/q) + np.sum(0.5*p_eta_baro**2/q_baro) + 0.5*p_eps**2/w_eps + temperature * ( g*eta[0] + np.sum(eta[1:])+ np.sum(eta_baro) ) # Extra terms for conserved variable eng = kin + total.pot # Total energy (cut-and-shifted) # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Internal energy (cut-and-shifted) per atom # Total KE plus total cut-and-shifted PE divided by N e_s = VariableType ( nam = 'E/N cut&shifted', val = eng/n ) # Internal energy (full, including LRC) per atom # LRC plus total KE plus total cut (but not shifted) PE divided by N e_f = VariableType ( nam = 'E/N full', val = potential_lrc(rho,r_cut) + (kin+total.cut)/n ) # Pressure (cut-and-shifted) # Ideal gas contribution plus total virial divided by V p_s = VariableType ( nam = 'P cut&shifted', val = rho*temperature + total.vir/vol ) # Pressure (full, including LRC) # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType ( nam = 'P full', val = pressure_lrc(rho,r_cut) + rho*temperature + total.vir/vol ) # Kinetic temperature t_k = VariableType ( nam = 'T kinetic', val = 2.0*kin/g ) # Configurational temperature # Total squared force divided by total Laplacian t_c = VariableType ( nam = 'T config', val = fsq/total.lap ) # Density density = VariableType ( nam = 'Density', val = rho ) # Conserved energy-like quantity per atom # Energy plus PV term plus extra terms defined above enp = eng + pressure*vol conserved = VariableType ( nam = 'Conserved/N', val = (enp+ext)/n ) # Volume MSD vol_msd = VariableType ( nam = 'Volume MSD', val = vol, method = msd, instant = False ) # Mean-squared deviation of conserved energy-like quantity # Energy plus PV term plus extra terms defined above enp = eng + pressure*vol conserved_msd = VariableType ( nam = 'Conserved MSD', val = (enp+ext)/n, method = msd, e_format = True, instant = False ) # Collect together into a list for averaging return [ e_s, p_s, e_f, p_f, t_k, t_c, density, conserved, vol_msd, conserved_msd ]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ # In this example we simulate using the cut (but not shifted) potential # but we only report results which have had the long-range corrections applied # The value of the cut-and-shifted potential is not used, in this example import numpy as np import math from averages_module import VariableType from lrc_module import potential_lrc, pressure_lrc # Preliminary calculations (n,r,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density kin = 1.5 * n * p * temperature # Average kinetic energy for NP-atom system kin_q = kin - total_spr # Quantum estimator for kinetic energy rad_g = rad_gyr(r) # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Acceptance ratio of atomic moves r_r = VariableType(nam='Atomic move ratio', val=r_ratio, instant=False) # Acceptance ratio of centre-of-mass moves c_r = VariableType(nam='COM move ratio', val=c_ratio, instant=False) # Internal energy per atom for full potential with LRC # LRC plus cut (but not shifted) PE already divided by factor P # plus KE estimator: total classical KE for NP-atom system MINUS total spring potential # all divided by N e_f = VariableType(nam='E/N full', val=potential_lrc(rho, r_cut) + (kin_q + total.pot) / n) # Kinetic energy per atom, just for interest's sake k_q = VariableType(nam='KE/N', val=kin_q / n) # Pressure for full potential with LRC # LRC plus ideal gas contribution plus total virial divided by V kin_q = kin_q / 1.5 # Convert KE estimator to kinetic energy part of pressure p_f = VariableType(nam='P full', val=pressure_lrc(rho, r_cut) + (kin_q + total.vir) / vol) # Quantum spring energy per atom, just for interest's sake e_q = VariableType(nam='Espring/N', val=total_spr / n) # Quantum polymer radius of gyration, just for interest's sake r_g = VariableType(nam='Radius of gyration', val=rad_g) # Collect together into a list for averaging return [r_r, c_r, e_f, p_f, e_q, k_q, r_g]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ # In this example we simulate using the cut (but not shifted) potential # The values of < p_c >, < e_c > and < density > should be consistent (for this potential) # For comparison, long-range corrections are also applied to give # estimates of < e_f > and < p_f > for the full (uncut) potential # The value of the cut-and-shifted potential is not used, in this example import numpy as np import math from averages_module import msd, VariableType from lrc_module import potential_lrc, pressure_lrc, pressure_delta from mc_lj_module import force_sq # Preliminary calculations (n,r,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density fsq = force_sq(box, r_cut, r) # Total squared force # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move, creation, and destruction acceptance ratios m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) c_r = VariableType(nam='Create ratio', val=c_ratio, instant=False) d_r = VariableType(nam='Destroy ratio', val=d_ratio, instant=False) # Number number = VariableType(nam='N', val=float(n)) # Density density = VariableType(nam='Density', val=rho) # Internal energy per atom for simulated, cut, potential # Ideal gas contribution plus cut (but not shifted) PE divided by N e_c = VariableType(nam='E/N cut', val=1.5 * temperature + total.pot / n) # Internal energy per atom for full potential with LRC # LRC plus ideal gas contribution plus cut (but not shifted) PE divided by N e_f = VariableType(nam='E/N full', val=potential_lrc(rho, r_cut) + 1.5 * temperature + total.pot / n) # Pressure for simulated, cut, potential # Delta correction plus ideal gas contribution plus total virial divided by V p_c = VariableType(nam='P cut', val=pressure_delta(rho, r_cut) + rho * temperature + total.vir / vol) # Pressure for full potential with LRC # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType(nam='P full', val=pressure_lrc(rho, r_cut) + rho * temperature + total.vir / vol) # Configurational temperature # Total squared force divided by total Laplacian t_c = VariableType(nam='T config', val=fsq / total.lap) # Number MSD n_msd = VariableType(nam='N MSD', val=float(n), method=msd, instant=False) # Collect together into a list for averaging return [m_r, c_r, d_r, number, density, e_c, p_c, e_f, p_f, t_c, n_msd]
def calc_variables ( ): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program.""" import numpy as np import math from averages_module import msd, cke, VariableType from lrc_module import potential_lrc, pressure_lrc from md_lj_module import hessian # Preliminary calculations (n,r,v,f,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density kin = 0.5*np.sum(v**2) # Kinetic energy tmp = 2.0 * kin / (3*n-3) # Remove three degrees of freedom for momentum conservation fsq = np.sum ( f**2 ) # Total squared force hes = hessian(box,r_cut,r,f) # Total Hessian eng = kin + total.pot # Total energy for simulated system # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Internal energy (cut-and-shifted) per atom # Total KE plus total cut-and-shifted PE divided by N e_s = VariableType ( nam = 'E/N cut&shifted', val = eng/n ) # Internal energy (full, including LRC) per atom # LRC plus total KE plus total cut (but not shifted) PE divided by N e_f = VariableType ( nam = 'E/N full', val = potential_lrc(rho,r_cut) + (kin+total.cut)/n ) # Pressure (cut-and-shifted) # Ideal gas contribution plus total virial divided by V p_s = VariableType ( nam = 'P cut&shifted', val = rho*tmp + total.vir/vol ) # Pressure (full, including LRC) # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType ( nam = 'P full', val = pressure_lrc(rho,r_cut) + rho*tmp + total.vir/vol ) # Kinetic temperature t_k = VariableType ( nam = 'T kinetic', val = tmp ) # Configurational temperature # Total squared force divided by total Laplacian with small Hessian correction t_c = VariableType ( nam = 'T config', val = fsq/(total.lap-(2.0*hes/fsq)) ) # MSD of kinetic energy, intensive # Use special method to convert to Cv/N c_s = VariableType ( nam = 'Cv/N cut&shifted', val = kin/math.sqrt(n), method = cke, instant = False ) # Mean-squared deviation of conserved energy per atom conserved_msd = VariableType ( nam = 'Conserved MSD', val = eng/n, method = msd, e_format = True, instant = False ) # Collect together into a list for averaging return [ e_s, p_s, e_f, p_f, t_k, t_c, c_s, conserved_msd ]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ # In this example we simulate using the cut (but not shifted) potential # Accordingly, < p_c > should match the input pressure and the values # of < p_c >, < e_c > and density should be consistent (for this potential) # For comparison, long-range corrections are also applied to give # estimates of < e_f > and < p_f > for the full (uncut) potential # The value of the cut-and-shifted potential is not used, in this example import numpy as np import math from averages_module import msd, VariableType from lrc_module import potential_lrc, pressure_lrc, pressure_delta from mc_lj_module import force_sq # Preliminary calculations (n,r,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density fsq = force_sq(box, r_cut, r) # Total squared force # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move and volume acceptance ratios m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) v_r = VariableType(nam='Volume ratio', val=v_ratio, instant=False) # Density density = VariableType(nam='Density', val=rho) # Internal energy per atom for simulated, cut, potential # Ideal gas contribution plus cut (but not shifted) PE divided by N e_c = VariableType(nam='E/N cut', val=1.5 * temperature + total.pot / n) # Internal energy per atom for full potential with LRC # LRC plus ideal gas contribution plus cut (but not shifted) PE divided by N e_f = VariableType(nam='E/N full', val=potential_lrc(rho, r_cut) + 1.5 * temperature + total.pot / n) # Pressure for simulated, cut, potential # Delta correction plus ideal gas contribution plus total virial divided by V p_c = VariableType(nam='P cut', val=pressure_delta(rho, r_cut) + rho * temperature + total.vir / vol) # Pressure for full potential with LRC # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType(nam='P full', val=pressure_lrc(rho, r_cut) + rho * temperature + total.vir / vol) # Configurational temperature # Total squared force divided by total Laplacian t_c = VariableType(nam='T config', val=fsq / total.lap) # Heat capacity (cut but not shifted) # MSD of excess "enthalpy" divided by temperature and sqrt(N) to make result intensive # NB this is not really the excess Cp/NkB, it simply omits the kinetic energy fluctuations # i.e. we add the ideal gas part of Cv/NkB, 1.5, to get total Cp/NkB enp = total.pot + pressure * vol c_c = VariableType(nam='Cp/N cut', val=enp / (temperature * math.sqrt(n)), method=msd, add=1.5, instant=False) # Heat capacity (full) # MSD of excess "enthalpy" divided by temperature and sqrt(N) to make result intensive # NB this is not really the excess Cp/NkB, it simply omits the kinetic energy fluctuations # i.e. we add the ideal gas part of Cv/NkB, 1.5, to get total Cp/NkB enp = n * potential_lrc(rho, r_cut) + total.pot + pressure * vol c_f = VariableType(nam='Cp/N full', val=enp / (temperature * math.sqrt(n)), method=msd, add=1.5, instant=False) # Volume MSD vol_msd = VariableType(nam='Volume MSD', val=vol, method=msd, instant=False) # Collect together into a list for averaging return [m_r, v_r, density, e_c, p_c, e_f, p_f, t_c, c_c, c_f, vol_msd]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ import numpy as np import math from averages_module import msd, VariableType from lrc_module import potential_lrc, pressure_lrc # Preliminary calculations (n,r,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density fsq = np.sum(f**2) # Total squared force # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move acceptance ratio m_r = VariableType(nam='Move ratio', val=m_ratio, instant=False) # Internal energy per atom for simulated, cut-and-shifted, potential # Ideal gas contribution plus total cut-and-shifted PE divided by N e_s = VariableType(nam='E/N cut&shifted', val=1.5 * temperature + total.pot / n) # Internal energy per atom for full potential with LRC # LRC plus ideal gas contribution plus total cut (but not shifted) PE divided by N e_f = VariableType(nam='E/N full', val=potential_lrc(rho, r_cut) + 1.5 * temperature + total.cut / n) # Pressure for simulated, cut-and-shifted, potential # Ideal gas contribution plus total virial divided by V p_s = VariableType(nam='P cut&shifted', val=rho * temperature + total.vir / vol) # Pressure for full potential with LRC # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType(nam='P full', val=pressure_lrc(rho, r_cut) + rho * temperature + total.vir / vol) # Configurational temperature # Total squared force divided by total Laplacian t_c = VariableType(nam='T config', val=fsq / total.lap) # Heat capacity (excess, cut-and-shifted) # Total PE divided by temperature and sqrt(N) to make result intensive # We add ideal gas contribution, 1.5, afterwards c_s = VariableType(nam='Cv/N cut&shifted', val=total.pot / (temperature * math.sqrt(n)), method=msd, add=1.5, instant=False) # Heat capacity (excess, full) # Total PE divided by temperature and sqrt(N) to make result intensive; LRC does not contribute # We add ideal gas contribution, 1.5, afterwards c_f = VariableType(nam='Cv/N full', val=total.cut / (temperature * math.sqrt(n)), method=msd, add=1.5, instant=False) # Collect together into a list for averaging return [m_r, e_s, p_s, e_f, p_f, t_c, c_s, c_f]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ from averages_module import msd, VariableType from lrc_module import potential_lrc, pressure_lrc import numpy as np import math # Preliminary calculations (n,v,f,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density kin = 0.5 * np.sum(v**2) # Kinetic energy fsq = np.sum(f**2) # Total squared force # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Internal energy (cut-and-shifted) per atom # Total KE plus total cut-and-shifted PE divided by N e_s = VariableType(nam='E/N cut&shifted', val=(kin + total.pot) / n) # Internal energy (full, including LRC) per atom # LRC plus total KE plus total cut (but not shifted) PE divided by N e_f = VariableType(nam='E/N full', val=potential_lrc(rho, r_cut) + (kin + total.cut) / n) # Pressure (cut-and-shifted) # Ideal gas contribution plus total virial divided by V p_s = VariableType(nam='P cut&shifted', val=rho * temperature + total.vir / vol) # Pressure (full, including LRC) # LRC plus ideal gas contribution plus total virial divided by V p_f = VariableType(nam='P full', val=pressure_lrc(rho, r_cut) + rho * temperature + total.vir / vol) # Kinetic temperature # Momentum is not conserved, hence 3N degrees of freedom t_k = VariableType(nam='T kinetic', val=2.0 * kin / (3 * n)) # Configurational temperature # Total squared force divided by total Laplacian t_c = VariableType(nam='T config', val=fsq / total.lap) # Heat capacity (cut-and-shifted) # Total energy divided by temperature and sqrt(N) to make result intensive c_s = VariableType(nam='Cv/N cut&shifted', val=(kin + total.pot) / (temperature * math.sqrt(n)), method=msd, instant=False) # Heat capacity (full) # Total energy divided by temperature and sqrt(N) to make result intensive; LRC does not contribute c_f = VariableType(nam='Cv/N full', val=(kin + total.cut) / (temperature * math.sqrt(n)), method=msd, instant=False) # Collect together into a list for averaging return [e_s, p_s, e_f, p_f, t_k, t_c, c_s, c_f]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program. """ # In this example we simulate using the cut (but not shifted) potential # The values of < p_c >, < e_c > and < density > should be consistent (for this potential) # For simplicity, long-range corrections are not applied here to give estimates of # < e_f > and < p_f > for the full (uncut) potential, but this is straightforward to do. # The value of the cut-and-shifted potential is not used, in this example import numpy as np import math from averages_module import VariableType from lrc_module import potential_lrc, pressure_lrc, pressure_delta # Preliminary calculations (n1,n2,r1,r2,etc are taken from the calling program) vol1 = box1**3 # Volume vol2 = box2**3 # Volume rho1 = n1 / vol1 # Density rho2 = n2 / vol2 # Density # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Move, swap, volume exchange acceptance ratios m1_r = VariableType(nam='Move ratio (1)', val=m1_ratio, instant=False) m2_r = VariableType(nam='Move ratio (2)', val=m2_ratio, instant=False) x12_r = VariableType(nam='Swap ratio (1->2)', val=x12_ratio, instant=False) x21_r = VariableType(nam='Swap ratio (2->1)', val=x21_ratio, instant=False) v_r = VariableType(nam='Volume ratio', val=v_ratio, instant=False) # Number of particles n_1 = VariableType(nam='Number (1)', val=float(n1)) n_2 = VariableType(nam='Number (2)', val=float(n2)) # Density density_1 = VariableType(nam='Density (1)', val=rho1) density_2 = VariableType(nam='Density (2)', val=rho2) # Internal energy per atom for simulated, cut, potential # Ideal gas contribution plus cut (but not shifted) PE divided by N e1_c = VariableType(nam='E/N cut (1)', val=1.5 * temperature + total1.pot / n1) e2_c = VariableType(nam='E/N cut (2)', val=1.5 * temperature + total2.pot / n2) # Pressure for simulated, cut, potential # Delta correction plus ideal gas contribution plus total virial divided by V p1_c = VariableType(nam='P cut (1)', val=pressure_delta(rho1, r_cut) + rho1 * temperature + total1.vir / vol1) p2_c = VariableType(nam='P cut (2)', val=pressure_delta(rho2, r_cut) + rho2 * temperature + total2.vir / vol2) # Collect together into a list for averaging return [ m1_r, m2_r, x12_r, x21_r, v_r, n_1, n_2, density_1, density_2, e1_c, e2_c, p1_c, p2_c ]
def calc_variables(): """Calculates all variables of interest. They are collected and returned as a list, for use in the main program.""" import numpy as np import math from averages_module import msd, VariableType from maths_module import q_to_a # Preliminary calculations (n,r,v,total are taken from the calling program) vol = box**3 # Volume rho = n / vol # Density kin_t = 0.5 * np.sum(v**2) # Translational kinetic energy kin_r = 0.0 for i, ei in enumerate(e): ai = q_to_a(ei) # Rotation matrix for i ell_i = np.dot(ai, ell[i, :]) # Get body-fixed angular momentum kin_r = kin_r + np.sum( (ell_i**2) / inertia) # Increment kinetic energy kin_r = kin_r / 2 # Rotational kinetic energy tmp_t = 2.0 * kin_t / ( 3 * n - 3) # Remove three degrees of freedom for momentum conservation tmp_r = 2.0 * kin_r / (3 * n) # 3N degrees of rotational freedom eng = kin_t + kin_r + total.pot # Total energy for simulated system # Variables of interest, of class VariableType, containing three attributes: # .val: the instantaneous value # .nam: used for headings # .method: indicating averaging method # If not set below, .method adopts its default value of avg # The .nam and some other attributes need only be defined once, at the start of the program, # but for clarity and readability we assign all the values together below # Internal energy (shifted-force potential) per atom # Total translational and rotational KE plus total PE divided by N if nvt: e_sf = VariableType(nam='E/N shifted force', val=3.0 * temperature + total.pot / n) else: e_sf = VariableType(nam='E/N shifted force', val=eng / n) # Pressure (shifted-force potential) # Ideal gas contribution plus total virial divided by V if nvt: p_sf = VariableType(nam='P shifted force', val=rho * temperature + total.vir / vol) else: p_sf = VariableType(nam='P shifted force', val=rho * tmp_t + total.vir / vol) # Kinetic translational temperature t_t = VariableType(nam='T translational', val=tmp_t) # Kinetic rotational temperature t_r = VariableType(nam='T rotational', val=tmp_r) # Mean-squared deviation of conserved energy per atom conserved_msd = VariableType(nam='Conserved MSD', val=eng / n, method=msd, e_format=True, instant=False) # Collect together into a list for averaging return [e_sf, p_sf, t_t, t_r, conserved_msd]