Esempio n. 1
0
    def test(self):
        space = feasst.Space(3)
        space.initBoxLength(8)
        pair = feasst.PairLJ(space, 3)  # potential truncation at 3
        molNameSS = space.install_dir() + "/forcefield/data.lj"
        pair.initData(molNameSS)  # initialize the sigma and epsilon

        # create clones of Space and Pair to perform two separate tests
        space2 = space.clone()
        pair2 = pair.clone(space2)

        # first, test the interaction between two particles
        xAdd = feasst.DoubleVector(space.dimen())  # position to add is origin
        pair.addMol(xAdd)  # add first molecule
        r = 1.2345
        xAdd[0] = r  # position of second particle
        pair.addMol(xAdd)  # add second particle
        pair.initEnergy()  # compute energy
        peExact = 4 * (pow(r, -12) - pow(r, -6))
        self.assertAlmostEqual(pair.peLJ(), peExact, 15)
        peExactLRC = (8./3.)*feasst.PI*space.nMol()**2/space.vol() \
          *((1./3.)*pair.rCut()**(-9) - pair.rCut()**(-3))
        self.assertAlmostEqual(pair.peLRC(), peExactLRC, 15)

        # second, compare with the reference configuration
        config = space.install_dir() + \
          "/testcase/1_lj/1_ref-config/lj_sample_config_periodic4.xyz"
        conf_file = feasst.make_ifstream(config)
        pair2.readxyz(conf_file)  # read the xyz file
        pair2.initEnergy()  # compute energy
        peLJ = -16.790321304625856
        peLRC = -0.5451660014945704
        self.assertAlmostEqual(pair2.peLRC(), peLRC, 15)
        self.assertAlmostEqual(pair2.peLJ(), peLJ, 15)
Esempio n. 2
0
def list_to_double_vector(lst):
    """ converts a python list to a swig stl vector """
    vec = feasst.DoubleVector(len(lst))
    for index in range(len(lst)):
        vec[index] = float(lst[index])
    return vec
Esempio n. 3
0
import pandas as pd
import argparse
import matplotlib.pyplot as plt
import feasst as fst
import pyfeasst

parser = argparse.ArgumentParser()
parser.add_argument("--file_name", "-f", type=str, help="file name", action='append', required=True)
parser.add_argument("--label", "-l", type=str, help="variable label", default='ln_prob')
parser.add_argument("--delta_conjugate", "-d", type=float, help="reweight by change in conjugate variable", default=0.)
args = parser.parse_args()
print(args.file_name)

for fname in args.file_name:
    df = pd.read_csv(fname, header=pyfeasst.line_beginning_with_state(fname))
    gce = fst.GrandCanonicalEnsemble(
        fst.Histogram(fst.args({"width": "1", "max": str(df["state"].iloc[-1]),
                                              "min": str(df["state"].iloc[0])})),
        fst.LnProbability(fst.DoubleVector(df["ln_prob"])))
    #print(df)
    #plt.plot(df['state'], df[args.label], label=fname)
    gce.reweight(args.delta_conjugate)
    plt.plot(df['state'], gce.ln_prob().values(), label=fname)
plt.legend()
plt.show()
# read checkpoints
num_procs = 12
clones = fst.MakeClones('checkpoint', num_procs)
volume = clones.clone(0).configuration().domain().volume()
beta = clones.clone(0).thermo_params().beta()
gce = pyfeasst.find_equilibrium(fst.GrandCanonicalEnsemble(clones))

# compute saturation pressure
R = clones.clone(0).configuration().physical_constants().ideal_gas_constant()
na = clones.clone(0).configuration().physical_constants().avogadro_constant()
press_conv = R / 1e3 * 1e30 / na
print('saturation pressure (kPa)', gce.betaPV() / volume / beta * press_conv)

# compute saturation compositions
num0 = fst.DoubleVector()
clones.stitch(num0, "NumParticles", fst.AccumulatorAverage())
num_vapor = gce.average(num0, 0)
num_liquid = gce.average(num0, 1)

print('vapor y_C2H4', 1 - num_vapor / gce.average_macrostate(0))
print('liquid x_C2H4', 1 - num_liquid / gce.average_macrostate(1))

# obtain extensive moments
extmom_index = fst.SeekAnalyze().index("ExtensiveMoments", clones.clone(0))[0]


# Return ExtensiveMoments, dervied class of Analyze, by serialization, which is relatively slow.
# see steppers/include/ExtensiveMoments.h for moments API
def extensive_moment(window, state):
    return fst.ExtensiveMoments(