-
Notifications
You must be signed in to change notification settings - Fork 6
11_Example_Input_Scripts
11 Example Input Scripts
This section contains a variety of example Ambuild input scripts, each of which involves the growth of a polymer from methane building blocks. There is one example of each of the growBlocks, joinBlocks, and zipBlocks scripts, in which the polymer is built solely from methane fragments, with no solvent, catalyst, or influence from other reagents (Sections 11.1-11.3, respectively). Additionally, some more advanced scripts are included to generate methane polymers in a statistical manner (Section 11.4) and an analysis script aimed to generate a trajectory from an Ambuild/HOOMD-blue optimisation and MD simulation that can be visualised as a DL_POLY version C HISTORY file using VMD (Section 11.5).
11.1 Example growBlocks Input Script
#!/usr/bin/env python3
#Our imports
from ambuild import ab_cell
#Cell Dimensions
boxDim=[30,30,30]
#Create the Cell
paramsDir='./params'
mycell = ab_cell.Cell(boxDim, atomMargin=0.1, bondMargin=0.5, bondAngleMargin=5, paramsDir=paramsDir )
#Add Fragments to the Library
mycell.libraryAddFragment( filename='./blocks/ch4.car', fragmentType='Me' )
#Specify Bonding Rules
mycell.addBondType( 'Me:a-Me:a' )
#Seed the Cell with the Building Blocks in the Library
mycell.seed( 1, fragmentType='Me' )
for i in range(100):
mycell.growBlocks(4, cellEndGroups='Me:a', libraryEndGroups='Me:a', maxTries=500)
mycell.optimiseGeometry(quiet=True)
mycell.dump()
mycell.runMD(doDihedral=True, rCut=10, mdCycles=1000000, T=55.0)
11.2 Example joinBlocks Input Script
#!/usr/bin/env python3
#Our imports
from ambuild import ab_cell
#Cell Dimensions
boxDim=[30,30,30]
#Create the Cell
paramsDir='./params'
mycell = ab_cell.Cell(boxDim, atomMargin=0.1, bondMargin=0.5, bondAngleMargin=5, paramsDir=paramsDir )
#Add Fragments to the Library
mycell.libraryAddFragment( filename='./blocks/ch4.car', fragmentType='Me' )
#Specify Bonding Rules
mycell.addBondType( 'Me:a-Me:a' )
#Seed the Cell with the Building Blocks in the Library
mycell.seed( 100, fragmentType='Me' )
mycell.optimiseGeometry(quiet=False)
for i in range(100):
mycell.joinBlocks(1, cellEndGroups=None, maxTries=500)
mycell.optimiseGeometry(quiet=False)
mycell.dump()
mycell.runMD(doDihedral=True, rCut=10, mdCycles=1000000, T=55.0)
11.3 Example zipBlocks Input Script
#!/usr/bin/env python3
#Our imports
from ambuild import ab_cell
#Cell Dimensions
boxDim=[30,30,30]
#Create the Cell
paramsDir='./params'
mycell = ab_cell.Cell(boxDim, atomMargin=0.1, bondMargin=0.5, bondAngleMargin=5, paramsDir=paramsDir )
#Add Fragments to the Library
mycell.libraryAddFragment( filename='./blocks/ch4.car', fragmentType='Me' )
#Specify Bonding Rules
mycell.addBondType( 'Me:a-Me:a' )
#Seed the Cell with the Building Blocks in the Library
mycell.seed( 100, fragmentType='Me' )
mycell.runMD(doDihedral=True, rCut=10, mdCycles=1000000, T=55.0)
mycell.optimiseGeometry(quiet=True)
for i in range(100):
mycell.zipBlocks(bondMargin=2.0, bondAngleMargin=30, clashCheck=False)
mycell.optimiseGeometry(quiet=True)
mycell.dump()
mycell.runMD(doDihedral=True, rCut=10, mdCycles=1000000, T=55.0)
11.4 Example Statistical Analysis Input Script
#!/usr/bin/env python3
from ambuild import ab_cell
from ambuild import ab_util
#Python imports
import csv
#Cell Dimensions
boxDim=[50,50,50]
#Create the Cell
paramsDir = 'Parameters'
mycell = ab_cell.Cell(boxDim, atomMargin=0.1, bondMargin=0.5, bondAngleMargin=5, paramsDir=paramsDir)
#Add Fragments to the Library
mycell.libraryAddFragment( filename='Blocks/ch4.car', fragmentType='CH4', markBonded=True)
#Specify Bonding Rules
mycell.addBondType( 'CH4:a-CH4:a' )
# keep a list of the configs
configs=[]
#loop to create 5 independent structures, each with 10 CH4 molecules
for i in range(5):
#Seed
mycell.seed(1, fragmentType='CH4', center=True)
#Grow and zip blocks
for i in range(9):
mycell.growBlocks(1, cellEndGroups=['CH4:a','CH4:a'], libraryEndGroups=['CH4:a','CH4:a'])
mycell.runMD(doDihedral=True, rCut=10, mdCycles=1000000, dt=0.0001, T=55.0, integrator='nvt')
mycell.optimiseGeometry(doDihedral=True, rCut=10, optCycles=1000000, dt=0.0001)
if mycell.zipBlocks(bondMargin=3, bondAngleMargin=80, selfBond=True, clashCheck=False) > 0:
mycell.cat1Paf2(['CH4','CH4'])
mycell.optimiseGeometry(doDihedral=True, rCut=10, optCycles=1000000, dt=0.0001)
mycell.dump()
# add the current endGroupConfig to the list, which gives the connectivity of each CH4 building block
# change the text in the string (e.g. 'CH4') to the fragmentType you want to write out.
configs.append(mycell.endGroupConfig('CH4'))
#Printing the configs as the script goes along.
print(configs)
#delete CH4 blocks to start the next cluster (10 pickle steps per cluster including delete step which should be empty and shouldn't write to config file!) Removing a maximum of 10 CH4 blocks as 10 were added, but in reality only one block should be removed as these are added using the grow method.
mycell.deleteBlocks(fragmentTypes='CH4', maxFrags=10)
mycell.dump()
# Create the csvfile with the data we've saved
with open("endGroupConfig.csv",'w') as f:
configWriter = csv.writer(f)
configWriter.writerow(['FileNumber','endGroupConfig'])
configWriter.writerows(configs)
11.5 Example Trajectory Analysis Input Script
Visualise this script using VMD, specifying the filetype as DL_POLY HISTORY C.