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_type=f3c:/feasst/plugin/models/test/data/f3c_o.txt xyz_file=two.xyz"}
write_xyz(params)
run_fst(params)
df = pd.read_csv(params['log']+'.csv')
assert 2 == df['num_particles_f3c'][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_type=f3c:/feasst/plugin/models/test/data/f3c_h.txt xyz_file=two.xyz"}
write_xyz(params)
run_fst(params)
df = pd.read_csv(params['log']+'.csv')
assert 2 == df['num_particles_f3c'][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_type=f3c_o:/feasst/plugin/models/test/data/f3c_o.txt,f3c_h:/feasst/plugin/models/test/data/f3c_h.txt 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_f3c_o'][0]
assert 1 == df['num_particles_f3c_h'][0]
assert np.abs(-0.0006260058345921262 + -23.35505043002061 - df['F3C'][0]) < 12
# Usage: /home/user/feasst/build/bin/fst < file.txt
FEASST version 0.25.13
MonteCarlo
Configuration particle_type=f3c:/feasst/plugin/models/test/data/f3c_o.txt xyz_file=two.xyz
Potential Asc=1 Model=F3C
ThermoParams beta=1000000
Metropolis
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:786] No Trials to attempt.
# Usage: /home/user/feasst/build/bin/fst < file.txt
FEASST version 0.25.13
MonteCarlo
Configuration particle_type=f3c:/feasst/plugin/models/test/data/f3c_h.txt xyz_file=two.xyz
Potential Asc=1 Model=F3C
ThermoParams beta=1000000
Metropolis
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:786] No Trials to attempt.
# Usage: /home/user/feasst/build/bin/fst < file.txt
FEASST version 0.25.13
MonteCarlo
Configuration add_particles_of_type0=1 add_particles_of_type1=1 particle_type=f3c_o:/feasst/plugin/models/test/data/f3c_o.txt,f3c_h:/feasst/plugin/models/test/data/f3c_h.txt xyz_file=two.xyz
# Renamed Site name:0->1 for particle_type:1 in:/home/user/feasst/plugin/models/test/data/f3c_h.txt
# Renamed Site type:0->1 for particle_type:1 in:/home/user/feasst/plugin/models/test/data/f3c_h.txt
Potential Asc=1 Model=F3C
ThermoParams beta=1000000
Metropolis
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:786] 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!