Force Field X with Mathematica
Force Field X with Mathematica
1. Prerequisites: Install Java and Add FFX to the Classpath
1. Prerequisites: Install Java and Add FFX to the Classpath
Force Field X depends on Java version 17 or greater. If your version of Mathematica is using an earlier version, please either
1) Set the “JAVA_HOME” environment variable to point to version 17 or greater, and then start Mathematica from the command line or
2) Edit the javacommand string below from
javacommand = “java “<>flags
to
javacommand = “/your/path/to/jdk/bin/java “<>flags
The first time this notebook is executed, ffx-all.jar will be downloaded to the Mathematica User Base DIrectory for reuse.
To update ffx-all.jar, please delete this file and it will be re-downloaded.
1) Set the “JAVA_HOME” environment variable to point to version 17 or greater, and then start Mathematica from the command line or
2) Edit the javacommand string below from
javacommand = “java “<>flags
to
javacommand = “/your/path/to/jdk/bin/java “<>flags
The first time this notebook is executed, ffx-all.jar will be downloaded to the Mathematica User Base DIrectory for reuse.
To update ffx-all.jar, please delete this file and it will be re-downloaded.
In[]:=
Quit;Needs["JLink`"];ffxVersion="1.0.0-beta";flags="-Dj3d.rend=noop -Djava.awt.headless=true";javacommand="java "<>flags;If[FailureQ[Environment["JAVA_HOME"]],,javacommand=Environment["JAVA_HOME"]<>"/bin/java "<>flags]ReinstallJava[CommandLinejavacommand,ClassPathNone];LoadJavaClass["java.lang.Runtime",StaticsVisibleTrue];"Java version: "<>version[]@toString[]SetDirectory[$UserBaseDirectory];ffxFile="forcefieldx-"<>ffxVersion<>".jar";If[FileExistsQ[ffxFile],"Using existing Force Field X jar file: "<>AbsoluteFileName[ffxFile],URLDownload["https://ffx.biochem.uiowa.edu/"<>ffxFile,File[ffxFile]]]AddToClassPath[AbsoluteFileName[ffxFile],"Prepend"True];"Current Directory: "<>ResetDirectory[]
Out[]=
Java version: 21+35-2513
Out[]=
Using existing Force Field X jar file: /Users/mjschnie/Library/Mathematica/forcefieldx-1.0.0-beta.jar
Out[]=
Current Directory: /Users/mjschnie
2. Load a Protein Databank File from the RCSB.
2. Load a Protein Databank File from the RCSB.
Download a file from the PDB and render it.
a.) Define a string with a 4-character PDB ID. This example uses the SARS-CoV-2 main protease.
b.) Import the file from the Protein Databank, and save it locally.
c.) Display an 2D image of the structure.
a.) Define a string with a 4-character PDB ID. This example uses the SARS-CoV-2 main protease.
b.) Import the file from the Protein Databank, and save it locally.
c.) Display an 2D image of the structure.
In[]:=
pdbID="1tf6";filename=pdbID<>".pdb";URLDownload["http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId="<>pdbID,filename];Import[filename,ImageSizeMedium]
Out[]=
3. Use Force Field X Command Line Syntax
3. Use Force Field X Command Line Syntax
Force Field X command line syntax consists of naming a script (e.g. “Energy” below) and passing an array of String arguments (e.g. filename below).JLink documentation: https://reference.wolfram.com/language/JLink/tutorial/Overview.htmlForce Field X documentation: https://ffx.biochem.uiowa.edu
In[]:=
LoadJavaClass["ffx.Main",StaticsVisibleTrue];script=ffxScript[{"Energy",filename}];forceFieldEnergy=script@forceFieldEnergy;forceFieldEnergy@toString[]
Out[]=
Bond Stretching 784.21711573 10167 0.002 ( 0.01372) Angle Bending 1923.49839878 18344 0.011 ( 2.48622) Stretch-Bend 28.64707121 16057 0.010 Out-of-Plane Bend 92.43149911 6120 0.003 Torsional Angle 1071.61936146 26972 0.013 Pi-Orbital Torsion 43.51567538 1543 0.001 Stretch-Torsion -7.21804026 364 0.000 Angle-Torsion -25.07425159 604 0.000 Torsion-Torsion -37.63520530 20 0.000 Van der Waals 185602571.96150760 5859255 0.360 Atomic Multipoles 129491208.86117943 1313976 Polarization -17207.68533436 1313976 1.922 Total Potential 315080447.13897717 (Kcal/mole) 2.325 (sec) Unit Cell 1260321788.55590870 Replicates Cell 1260321788.55590870
4. Use JLink Syntax to Use the Force Field X
4. Use JLink Syntax to Use the Force Field X
Alternatively, more precise control is possible using JLink Syntax to use the entire Force Field X API.
a.) An ArrayList (list) is created and loaded with String arguments.
b.) A Groovy Binding is created, and the "args" property is set to the list.
c.) The Energy script is created, loaded with the Groovy Binding, and its run method called.
d.) Finally, the toString method of the Energy script field "forceFieldEnergy" is called.
a.) An ArrayList (list) is created and loaded with String arguments.
b.) A Groovy Binding is created, and the "args" property is set to the list.
c.) The Energy script is created, loaded with the Groovy Binding, and its run method called.
d.) Finally, the toString method of the Energy script field "forceFieldEnergy" is called.
In[]:=
list=JavaNew["java.util.ArrayList"];list@add[JavaNew["java.lang.String",filename]];binding=JavaNew["groovy.lang.Binding"];binding@setProperty["args",list];script=JavaNew["ffx.potential.groovy.Energy"];script@setBinding[binding];script@run[];forceFieldEnergy=script@forceFieldEnergy;forceFieldEnergy@toString[]
Out[]=
Bond Stretching 784.21711573 10167 0.001 ( 0.01372) Angle Bending 1923.49839878 18344 0.002 ( 2.48622) Stretch-Bend 28.64707121 16057 0.001 Out-of-Plane Bend 92.43149911 6120 0.005 Torsional Angle 1071.61936146 26972 0.002 Pi-Orbital Torsion 43.51567538 1543 0.004 Stretch-Torsion -7.21804026 364 0.001 Angle-Torsion -25.07425159 604 0.001 Torsion-Torsion -37.63520530 20 0.000 Van der Waals 185602571.96150765 5859255 0.306 Atomic Multipoles 129491208.86117943 1313976 Polarization -17207.68533437 1313976 0.675 Total Potential 315080447.13897720 (Kcal/mole) 0.997 (sec) Unit Cell 1260321788.55590900 Replicates Cell 1260321788.55590900