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
This file is available in the Force Field X distribution “mathematica” directory and on GitHub at:
https://github.com/SchniedersLab/forcefieldx/blob/master/mathematica/ForceFieldX.nb
Force Field X depends on Java version 25. If your version of Mathematica is using an earlier version, please either
1) Set the “JAVA_HOME” environment variable to point to version 25, and then start Mathematica from the command line
or
2) Edit the javacommand string below from
javacommand = “/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home/bin/java “<>flags;
to
javacommand = “/your/path/to/jdk/bin/java “<>flags;
The first time this notebook is executed, FFX will be downloaded to the Mathematica User Base DIrectory for reuse.
To update FFX, please delete this file and it will be re-downloaded.
https://github.com/SchniedersLab/forcefieldx/blob/master/mathematica/ForceFieldX.nb
Force Field X depends on Java version 25. If your version of Mathematica is using an earlier version, please either
1) Set the “JAVA_HOME” environment variable to point to version 25, and then start Mathematica from the command line
or
2) Edit the javacommand string below from
javacommand = “/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home/bin/java “<>flags;
to
javacommand = “/your/path/to/jdk/bin/java “<>flags;
The first time this notebook is executed, FFX will be downloaded to the Mathematica User Base DIrectory for reuse.
To update FFX, please delete this file and it will be re-downloaded.
In[]:=
Quit;Needs["JLink`"];ffxVersion="26.0.2";flags="-Dj3d.rend=noop -Djava.awt.headless=true --add-modules jdk.incubator.vector";javacommand="/Library/Java/JavaVirtualMachines/jdk-25.jdk/Contents/Home/bin/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="ffx-"<>ffxVersion<>"-bin.tar.gz";If[FileExistsQ[ffxFile],"Using existing Force Field X download: "<>AbsoluteFileName[ffxFile],ExtractArchive[URLDownload["https://ffx.biochem.uiowa.edu/"<>ffxFile,File[ffxFile]]]];ffxLibDir="ffx-"<>ffxVersion<>"/lib";AddToClassPath[AbsoluteFileName[ffxLibDir],"Prepend"True];"Current Directory: "<>ResetDirectory[]
Out[]=
Java version: 25+36-3489
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="1BNA";filename=pdbID<>".pdb"URLDownload["http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=pdb&compression=NO&structureId="<>pdbID,filename]Import[filename,ImageSizeMedium]
Out[]=
1BNA.pdb
Out[]=
File
Out[]=
BioMolecule
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];(*LoadtheFFXMainclassanditsstaticmethods.*)command=ffxScript[{"Energy",filename}];(*UsetheffxScriptstaticmethodtoruntheEnergycommand.*)forceFieldEnergy=command@forceFieldEnergy;(*CollectareferencetotheForceFieldEnergyinstanceoftheEnergycommend.*)forceFieldEnergy@toString[](*Logtheresultforeachenergyterm.*)
Out[]=
Bond Stretching 104.71188695 976 0.001 ( 0.01669) Angle Bending 330.00061577 1556 0.002 ( 3.35761) Stretch-Bend 1.82412339 1246 0.001 Urey-Bradley -0.12349295 80 0.000 Out-of-Plane Bend 0.34878178 432 0.000 Torsional Angle -28.96931600 2156 0.001 Stretch-Torsion 0.06914191 68 0.000 Angle-Torsion -6.16994404 112 0.000 Pi-Orbital Torsion 0.84096434 140 0.000 Van der Waals 1360.46674832 224997 0.034 Atomic Multipoles -3552.64106088 52803 Polarization -404.31559872 52803 1.158 Total Potential -2193.95715012 (Kcal/mole) 1.198 (sec) Unit Cell -8775.82860049 Replicates Cell -17551.65720097
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.
In[]:=
args=MakeJavaObject[{filename}];(*CreateanString[]instancewithoneentry.*)command=JavaNew["ffx.potential.commands.Energy",args];(*CreateaninstanceoftheEnergycommandpassinginarguments.*)command@run[];(*Runthecommand.*)forceFieldEnergy=command@forceFieldEnergy;(*CollectareferencetotheForceFieldEnergyinstanceoftheEnergycommend.*)forceFieldEnergy@toString[](*Logtheresultforeachenergyterm.*)
Out[]=
Bond Stretching 104.71188695 976 0.000 ( 0.01669) Angle Bending 330.00061577 1556 0.001 ( 3.35761) Stretch-Bend 1.82412339 1246 0.001 Urey-Bradley -0.12349295 80 0.000 Out-of-Plane Bend 0.34878178 432 0.001 Torsional Angle -28.96931600 2156 0.001 Stretch-Torsion 0.06914191 68 0.000 Angle-Torsion -6.16994404 112 0.000 Pi-Orbital Torsion 0.84096434 140 0.000 Van der Waals 1360.46674832 224997 0.031 Atomic Multipoles -3552.64106088 52803 Polarization -404.31559872 52803 0.277 Total Potential -2193.95715012 (Kcal/mole) 0.312 (sec) Unit Cell -8775.82860049 Replicates Cell -17551.65720097