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]
Exemplo n.º 3
0
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 ]
Exemplo n.º 4
0
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]
Exemplo n.º 7
0
mu = temperature * ( np.log(density) + a_res[0,0] + a_res[0,1] )
z  = density * np.exp ( a_res[0,0] + a_res[0,1] )
print('')
print ( "{:40}{:15.6f}".format('Pressure P',            p  ) )
print ( "{:40}{:15.6f}".format('Energy E/N',            e  ) )
print ( "{:40}{:15.6f}".format('Heat capacity Cv/NkB',  cv ) )
print ( "{:40}{:15.6f}".format('Heat capacity Cp/NkB',  cp ) )
print ( "{:40}{:15.6f}".format('Chemical potential mu', mu ) )
print ( "{:40}{:15.6f}".format('Activity z',            z  ) )

# Estimates for cut (but not shifted) potential by reverse-application of long-range & delta corrections
print('')
print('Lennard-Jones potential cut (but not shifted) at 2.5 sigma')

p  = p - pressure_lrc ( density, r_cut ) + pressure_delta ( density, r_cut )
e  = e - potential_lrc ( density, r_cut )
mu = mu - 2.0 * potential_lrc ( density, r_cut )
z  = z * np.exp ( -2.0* potential_lrc ( density, r_cut ) / temperature )
print('')
print ( "{:40}{:15.6f}".format('Pressure P',            p  ) )
print ( "{:40}{:15.6f}".format('Energy E/N',            e  ) )
print ( "{:40}{:15.6f}".format('Chemical potential mu', mu ) )
print ( "{:40}{:15.6f}".format('Activity z',            z  ) )

# Results for cut-and-shifted potential from Thol et al (2015) fitting formula
print('')
print('Lennard-Jones potential cut-and-shifted at 2.5 sigma')
print('')

a_res = a_res_cutshift ( temperature, 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 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 ]