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 unittest
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 > launch0.log", 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))

class TestMonteCarloF3COxygenRef(unittest.TestCase):
    def test_two_oxygen_sites(self):
        """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')
        self.assertEqual(2, df['num_particles_of_type0'][0])
        self.assertAlmostEqual(-0.041567117565916176 + 46.71010086004122, df['F3C'][0], 12)

    def test_two_hydrogen_sites(self):
        """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')
        self.assertEqual(2, df['num_particles_of_type0'][0])
        self.assertAlmostEqual(-6.377176514562533e-07 + 11.677525215010306, df['F3C'][0], 12)

    def test_oxygen_hydrogen_sites(self):
        """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')
        self.assertEqual(1, df['num_particles_of_type0'][0])
        self.assertEqual(1, df['num_particles_of_type1'][0])
        self.assertAlmostEqual(-0.0006260058345921262 + -23.35505043002061, df['F3C'][0], 12)

unittest.main(argv=[''], verbosity=2, exit=False)


test_oxygen_hydrogen_sites (__main__.TestMonteCarloF3COxygenRef.test_oxygen_hydrogen_sites)
Test the LJ potential against analytical calculation of an oxygen and hydrogen site ... ok
test_two_hydrogen_sites (__main__.TestMonteCarloF3COxygenRef.test_two_hydrogen_sites)
Test the LJ potential against analytical calculation of two hydrogen sites ... ok
test_two_oxygen_sites (__main__.TestMonteCarloF3COxygenRef.test_two_oxygen_sites)
Test the F3C potential against analytical calculation of two oyxgen sites ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.030s

OK
[1]:
<unittest.main.TestProgram at 0x7f6b0f959310>

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