1 // ****************************************************************************** 2 // 3 // Title: Force Field X. 4 // Description: Force Field X - Software for Molecular Biophysics. 5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2025. 6 // 7 // This file is part of Force Field X. 8 // 9 // Force Field X is free software; you can redistribute it and/or modify it 10 // under the terms of the GNU General Public License version 3 as published by 11 // the Free Software Foundation. 12 // 13 // Force Field X is distributed in the hope that it will be useful, but WITHOUT 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 // details. 17 // 18 // You should have received a copy of the GNU General Public License along with 19 // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple 20 // Place, Suite 330, Boston, MA 02111-1307 USA 21 // 22 // Linking this library statically or dynamically with other modules is making a 23 // combined work based on this library. Thus, the terms and conditions of the 24 // GNU General Public License cover the whole combination. 25 // 26 // As a special exception, the copyright holders of this library give you 27 // permission to link this library with independent modules to produce an 28 // executable, regardless of the license terms of these independent modules, and 29 // to copy and distribute the resulting executable under terms of your choice, 30 // provided that you also meet, for each linked independent module, the terms 31 // and conditions of the license of that module. An independent module is a 32 // module which is not derived from or based on this library. If you modify this 33 // library, you may extend this exception to your version of the library, but 34 // you are not obligated to do so. If you do not wish to do so, delete this 35 // exception statement from your version. 36 // 37 // ****************************************************************************** 38 package ffx.openmm.amoeba; 39 40 import com.sun.jna.ptr.IntByReference; 41 import com.sun.jna.ptr.PointerByReference; 42 import ffx.openmm.Force; 43 44 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion; 45 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_create; 46 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_destroy; 47 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_getNumTorsionTorsionGrids; 48 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_getNumTorsionTorsions; 49 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_getTorsionTorsionGrid; 50 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_getTorsionTorsionParameters; 51 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionGrid; 52 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionParameters; 53 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_setUsesPeriodicBoundaryConditions; 54 import static edu.uiowa.jopenmm.OpenMMAmoebaLibrary.OpenMM_AmoebaTorsionTorsionForce_usesPeriodicBoundaryConditions; 55 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Boolean.OpenMM_True; 56 57 /** 58 * This class implements the Amoeba torsion-torsion interaction. 59 * <p> 60 * To use it, create an AmoebaTorsionTorsionForce object then call addTorsionTorsion() once for each torsion-torsion. After 61 * a torsion-torsion has been added, you can modify its force field parameters by calling setTorsionTorsionParameters(). 62 */ 63 public class TorsionTorsionForce extends Force { 64 65 /** 66 * Create an AmoebaTorsionTorsionForce. 67 */ 68 public TorsionTorsionForce() { 69 super(OpenMM_AmoebaTorsionTorsionForce_create()); 70 } 71 72 /** 73 * Add a torsion-torsion term to the force field. 74 * 75 * @param particle1 the index of the first particle connected by the torsion-torsion 76 * @param particle2 the index of the second particle connected by the torsion-torsion 77 * @param particle3 the index of the third particle connected by the torsion-torsion 78 * @param particle4 the index of the fourth particle connected by the torsion-torsion 79 * @param particle5 the index of the fifth particle connected by the torsion-torsion 80 * @param chiralCheckAtomIndex the index of the particle connected to particle3, but not particle2 or particle4 to be used in chirality check 81 * @param gridIndex the index to the grid to be used 82 * @return the index of the torsion-torsion that was added 83 */ 84 public int addTorsionTorsion(int particle1, int particle2, int particle3, int particle4, int particle5, int chiralCheckAtomIndex, int gridIndex) { 85 return OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion(pointer, particle1, particle2, particle3, particle4, particle5, chiralCheckAtomIndex, gridIndex); 86 } 87 88 /** 89 * Destroy the Amoeba Torsion-Torsion Force. 90 */ 91 @Override 92 public void destroy() { 93 if (pointer != null) { 94 OpenMM_AmoebaTorsionTorsionForce_destroy(pointer); 95 pointer = null; 96 } 97 } 98 99 /** 100 * Get the number of torsion-torsion terms in the potential function 101 * 102 * @return the number of torsion-torsion terms 103 */ 104 public int getNumTorsionTorsions() { 105 return OpenMM_AmoebaTorsionTorsionForce_getNumTorsionTorsions(pointer); 106 } 107 108 /** 109 * Get the number of torsion-torsion grids 110 * 111 * @return the number of torsion-torsion grids 112 */ 113 public int getNumTorsionTorsionGrids() { 114 return OpenMM_AmoebaTorsionTorsionForce_getNumTorsionTorsionGrids(pointer); 115 } 116 117 /** 118 * Get the force field parameters for a torsion-torsion term. 119 * 120 * @param index the index of the torsion-torsion for which to get parameters 121 * @param particle1 the index of the first particle connected by the torsion-torsion 122 * @param particle2 the index of the second particle connected by the torsion-torsion 123 * @param particle3 the index of the third particle connected by the torsion-torsion 124 * @param particle4 the index of the fourth particle connected by the torsion-torsion 125 * @param particle5 the index of the fifth particle connected by the torsion-torsion 126 * @param chiralCheckAtomIndex the index of the particle connected to particle3, but not particle2 or particle4 to be used in chirality check 127 * @param gridIndex the grid index 128 */ 129 public void getTorsionTorsionParameters(int index, IntByReference particle1, IntByReference particle2, 130 IntByReference particle3, IntByReference particle4, IntByReference particle5, 131 IntByReference chiralCheckAtomIndex, IntByReference gridIndex) { 132 OpenMM_AmoebaTorsionTorsionForce_getTorsionTorsionParameters(pointer, index, particle1, particle2, particle3, 133 particle4, particle5, chiralCheckAtomIndex, gridIndex); 134 } 135 136 /** 137 * Get the torsion-torsion grid at the specified index 138 * 139 * @param index the grid index 140 * @return grid return grid reference 141 */ 142 public PointerByReference getTorsionTorsionGrid(int index) { 143 return OpenMM_AmoebaTorsionTorsionForce_getTorsionTorsionGrid(pointer, index); 144 } 145 146 /** 147 * Set the force field parameters for a torsion-torsion term. 148 * 149 * @param index the index of the torsion-torsion for which to set parameters 150 * @param particle1 the index of the first particle connected by the torsion-torsion 151 * @param particle2 the index of the second particle connected by the torsion-torsion 152 * @param particle3 the index of the third particle connected by the torsion-torsion 153 * @param particle4 the index of the fourth particle connected by the torsion-torsion 154 * @param particle5 the index of the fifth particle connected by the torsion-torsion 155 * @param chiralCheckAtomIndex the index of the particle connected to particle3, but not particle2 or particle4 to be used in chirality check 156 * @param gridIndex the grid index 157 */ 158 public void setTorsionTorsionParameters(int index, int particle1, int particle2, int particle3, 159 int particle4, int particle5, int chiralCheckAtomIndex, int gridIndex) { 160 OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionParameters(pointer, index, particle1, particle2, particle3, 161 particle4, particle5, chiralCheckAtomIndex, gridIndex); 162 } 163 164 /** 165 * Set the torsion-torsion grid at the specified index 166 * 167 * @param gridIndex the index of the torsion-torsion for which to get parameters 168 * @param grid either 3 or 6 values may be specified per grid point. If the derivatives 169 * are omitted, they are calculated automatically by fitting a 2D spline to 170 * the energies. 171 * grid[x][y][0] = x value 172 * grid[x][y][1] = y value 173 * grid[x][y][2] = energy 174 * grid[x][y][3] = dEdx value 175 * grid[x][y][4] = dEdy value 176 * grid[x][y][5] = dEd(xy) value 177 */ 178 public void setTorsionTorsionGrid(int gridIndex, PointerByReference grid) { 179 OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionGrid(pointer, gridIndex, grid); 180 } 181 182 /** 183 * Set whether this force should apply periodic boundary conditions when calculating displacements. 184 * Usually this is not appropriate for bonded forces, but there are situations when it can be useful. 185 * 186 * @param periodic if true, periodic boundary conditions will be used 187 */ 188 public void setUsesPeriodicBoundaryConditions(boolean periodic) { 189 OpenMM_AmoebaTorsionTorsionForce_setUsesPeriodicBoundaryConditions(pointer, periodic ? 1 : 0); 190 } 191 192 /** 193 * Returns whether or not this force makes use of periodic boundary 194 * conditions. 195 * 196 * @return true if force uses PBC and false otherwise 197 */ 198 @Override 199 public boolean usesPeriodicBoundaryConditions() { 200 int pbc = OpenMM_AmoebaTorsionTorsionForce_usesPeriodicBoundaryConditions(pointer); 201 return pbc == OpenMM_True; 202 } 203 }