Simulation of a single 20-bead linear chain

[1]:
import unittest
import copy
import math
import numpy as np
import pandas as pd

script="""
MonteCarlo
Configuration cubic_side_length 30 \
              particle_type0 /feasst/plugin/chain/particle/chain20.fstprt
Potential Model LennardJones VisitModel VisitModelIntra intra_cut 1
ThermoParams beta 1 chemical_potential0 1
Metropolis
TrialAdd particle_type 0
Run until_num_particles 1
RemoveTrial name TrialAdd
TrialPivot weight 1 tunable_param 20 max_length 8
TrialCrankshaft weight 1 tunable_param 20 max_length 8
TrialGrowFile grow_file grow_chain20.txt
set_variable trials_per 1e4
Log trials_per_write trials_per output_file chain.txt
Movie trials_per_write trials_per output_file chain.xyz
Energy trials_per_write trials_per output_file chain_en.txt
CheckEnergy trials_per_update trials_per tolerance 1e-10
Tune
Run num_trials 1e3
EndToEndDistance output_file end_to_end.txt
RadiusOfGyration output_file rg.txt
Run num_trials 1e5
"""

# create grow_chain20.txt
unit_grows = list()
grows=list()
length=20
max_length=19
for i in range(max_length):
     unit_grows.append("bond true mobile_site "+str(i)+" anchor_site "+str(i+1)+" num_steps 4\n")
     if i == 0:
         grows.append(unit_grows[-1])
     else:
         grows.append(unit_grows[-1] + copy.deepcopy(grows[-1]))
unit_grows = list()
for i in range(max_length):
    unit_grows.append("bond true mobile_site "+str(length-i-1)+" anchor_site "+str(length-i-2)+'\n')
    if i == 0:
        grows.append(unit_grows[-1])
    else:
        grows.append(unit_grows[-1] + copy.deepcopy(grows[-1]))
for ind, grow in enumerate(grows):
    grows[ind] = "weight "+str(1./len(grow))+" "+grows[ind]
    grows[ind] = "particle_type 0 " + grows[ind]
with open('grow_chain20.txt', 'w') as file:
    file.write('TrialGrowFile\n\n')
    for grow in grows:
        file.write(grow+'\n')

with open('script.txt', 'w') as file: file.write(script)
import subprocess
syscode = subprocess.call("../../../build/bin/fst < script.txt > script.log", shell=True, executable='/bin/bash')
with open('script.log', 'r') as file: print(file.read(), '\n', 'exit:', syscode)
# FEASST version: v0.24.2-6-gf3cf33172b-dirty-hwh/whatnow
MonteCarlo
Configuration cubic_side_length 30 particle_type0 /home/hwh/feasst/plugin/chain/particle/chain20.fstprt
Potential Model LennardJones VisitModel VisitModelIntra intra_cut 1
ThermoParams beta 1 chemical_potential0 1
Metropolis
TrialAdd particle_type 0
Run until_num_particles 1
# initializing random number generator with seed: 1702503297
RemoveTrial name TrialAdd
TrialPivot max_length 8 tunable_param 20 weight 1
TrialCrankshaft max_length 8 tunable_param 20 weight 1
TrialGrowFile grow_file grow_chain20.txt
Log output_file chain.txt trials_per_write 1e4
Movie output_file chain.xyz trials_per_write 1e4
Energy output_file chain_en.txt trials_per_write 1e4
CheckEnergy tolerance 1e-10 trials_per_update 1e4
Tune
Run num_trials 1e3
EndToEndDistance output_file end_to_end.txt
RadiusOfGyration output_file rg.txt
Run num_trials 1e5

 exit: 0
[2]:
class TestChain20RG(unittest.TestCase):
    def test_rg_en(self):
        rg=pd.read_csv('rg.txt')
        self.assertAlmostEqual(np.sqrt(2.45), rg['average'][0], delta=4*rg['block_stdev'][0])
        end_to_end=pd.read_csv('end_to_end.txt')
        self.assertAlmostEqual(2.92, end_to_end['average'][0], delta=4*end_to_end['block_stdev'][0])
        en=pd.read_csv('chain_en.txt')
        self.assertAlmostEqual(-29.4, en['average'][0], delta=4*en['block_stdev'][0])
unittest.main(argv=[''], verbosity=2, exit=False)
test_rg_en (__main__.TestChain20RG) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.004s

OK
[2]:
<unittest.main.TestProgram at 0x7fd19f02de10>

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