F3C potential test

In this example, the potential energy between two sites is compared to the analytical value.

[1]:
import math
import sys
import subprocess
import numpy as np
import pandas as pd

def run_fst(params):
    """ Run a feasst simulation with the given parameters """
    with open("launch0.txt", "w") as myfile: myfile.write("""
MonteCarlo
Configuration {config_params}
Potential Model F3C Asc 1
ThermoParams beta 1000000
Metropolis
Log output_file {log}.csv max_precision true clear_file true
Run num_trials 1
""".format(**params))
    syscode = subprocess.call("../../../build/bin/fst < launch0.txt", shell=True, executable='/bin/bash')
    if syscode > 0: sys.exit(1)

def write_xyz(params):
    """ Write an xyz file"""
    with open("two.xyz", "w") as myfile: myfile.write(
"""2
-1 20 20 20
0 0 0 0
1 0 0 {displacement}""".format(**params))

"""Test the F3C potential against analytical calculation of two oyxgen sites"""
params = {"displacement": 5, "log": "f3c_o",
          "config_params": "particle_type0 /feasst/plugin/models/test/data/f3c_o.fstprt xyz_file two.xyz"}
write_xyz(params)
run_fst(params)
df = pd.read_csv(params['log']+'.csv')
assert 2 == df['num_particles_of_type0'][0]
assert np.abs(-0.041567117565916176 + 46.71010086004122 - df['F3C'][0]) < 12

"""Test the LJ potential against analytical calculation of two hydrogen sites"""
params = {"displacement": 5, "log": "f3c_h",
          "config_params": "particle_type0 /feasst/plugin/models/test/data/f3c_h.fstprt xyz_file two.xyz"}
write_xyz(params)
run_fst(params)
df = pd.read_csv(params['log']+'.csv')
assert 2 == df['num_particles_of_type0'][0]
assert np.abs(-6.377176514562533e-07 + 11.677525215010306 - df['F3C'][0]) < 12

"""Test the LJ potential against analytical calculation of an oxygen and hydrogen site"""
params = {"displacement": 5, "log": "f3c_h",
          "config_params": "particle_type0 /feasst/plugin/models/test/data/f3c_o.fstprt particle_type1 /feasst/plugin/models/test/data/f3c_h.fstprt add_particles_of_type0 1 add_particles_of_type1 1 xyz_file two.xyz"}
write_xyz(params)
run_fst(params)
df = pd.read_csv(params['log']+'.csv')
assert 1 == df['num_particles_of_type0'][0]
assert 1 == df['num_particles_of_type1'][0]
assert np.abs(-0.0006260058345921262 + -23.35505043002061 - df['F3C'][0]) < 12
# Usage: ./fst < file.txt
FEASST version 0.25.6
MonteCarlo
Configuration particle_type0 /home/user/feasst/plugin/models/test/data/f3c_o.fstprt xyz_file two.xyz
Potential Asc 1 Model F3C
ThermoParams beta 1000000
Metropolis
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -0.0415671
#Info 0 [plugin/models/src/f3c.cpp:68] en_q 46.7101
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -0.0415671
#Info 0 [plugin/models/src/f3c.cpp:68] en_q 46.7101
Log clear_file true max_precision true output_file f3c_o.csv
Run num_trials 1
#Warn 0 [plugin/monte_carlo/src/monte_carlo.cpp:744] No Trials to attempt.
# Usage: ./fst < file.txt
FEASST version 0.25.6
MonteCarlo
Configuration particle_type0 /home/user/feasst/plugin/models/test/data/f3c_h.fstprt xyz_file two.xyz
Potential Asc 1 Model F3C
ThermoParams beta 1000000
Metropolis
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -6.37718e-07
#Info 0 [plugin/models/src/f3c.cpp:68] en_q 11.6775
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -6.37718e-07
#Info 0 [plugin/models/src/f3c.cpp:68] en_q 11.6775
Log clear_file true max_precision true output_file f3c_h.csv
Run num_trials 1
#Warn 0 [plugin/monte_carlo/src/monte_carlo.cpp:744] No Trials to attempt.
# Usage: ./fst < file.txt
FEASST version 0.25.6
MonteCarlo
Configuration add_particles_of_type0 1 add_particles_of_type1 1 particle_type0 /home/user/feasst/plugin/models/test/data/f3c_o.fstprt particle_type1 /home/user/feasst/plugin/models/test/data/f3c_h.fstprt xyz_file two.xyz
Potential Asc 1 Model F3C
ThermoParams beta 1000000
Metropolis
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -0.000626006
#Info 0 [plugin/models/src/f3c.cpp:68] en_q -23.3551
#Info 0 [plugin/models/src/f3c.cpp:67] en_lj -0.000626006
#Info 0 [plugin/models/src/f3c.cpp:68] en_q -23.3551
Log clear_file true max_precision true output_file f3c_h.csv
Run num_trials 1
#Warn 0 [plugin/monte_carlo/src/monte_carlo.cpp:744] No Trials to attempt.

Did this tutorial work as expected? Did you find any inconsistencies or have any comments? Please contact us. Any feedback is appreciated!