1 // ****************************************************************************** 2 // 3 // Title: Force Field X. 4 // Description: Force Field X - Software for Molecular Biophysics. 5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2024. 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.algorithms; 39 40 import ffx.algorithms.dynamics.MolecularDynamics; 41 import ffx.algorithms.dynamics.integrators.IntegratorEnum; 42 import ffx.algorithms.dynamics.thermostats.ThermostatEnum; 43 import ffx.algorithms.optimize.Minimize; 44 import ffx.numerics.Potential; 45 import ffx.potential.MolecularAssembly; 46 import ffx.potential.utils.PotentialsUtils; 47 48 import java.io.File; 49 import java.util.logging.Logger; 50 51 /** 52 * AlgorithmUtils, on top of the core functionality of PotentialsUtils, implements additional 53 * functionality such as molecular dynamics and L-BFGS local optimization. This implementation does 54 * not do anything on top of what is specified by the interface, and is used primarily by tests. It 55 * is also potentially useful for third parties who would like to use FFX without its graphical user 56 * interface. 57 * 58 * @author Jacob M. Litman 59 * @author Michael J. Schnieders 60 */ 61 public class AlgorithmUtils extends PotentialsUtils implements AlgorithmFunctions { 62 63 private static final Logger logger = Logger.getLogger(AlgorithmUtils.class.getName()); 64 private final long initTime; 65 private long interTime; 66 67 /** Constructor for AlgorithmUtils. */ 68 public AlgorithmUtils() { 69 initTime = System.nanoTime(); 70 interTime = initTime; 71 } 72 73 /** 74 * {@inheritDoc} 75 * 76 * <p>Performs molecular dynamics on a MolecularAssembly. 77 */ 78 @Override 79 public void md(MolecularAssembly assembly, int nStep, double timeStep, double printInterval, 80 double saveInterval, double temperature, boolean initVelocities, File dyn) { 81 if (assembly == null) { 82 logger.info(" No active system to minimize."); 83 } else { 84 MolecularDynamics molecularDynamics = new MolecularDynamics(assembly, 85 assembly.getPotentialEnergy(), null, ThermostatEnum.BUSSI, IntegratorEnum.BEEMAN); 86 molecularDynamics.dynamic(nStep, timeStep, printInterval, saveInterval, temperature, 87 initVelocities, dyn); 88 } 89 } 90 91 /** 92 * {@inheritDoc} 93 * 94 * <p>Minimizes a MolecularAssembly using AMOEBA potential energy. 95 */ 96 @Override 97 public Potential minimize(MolecularAssembly assembly, double eps) { 98 if (assembly == null) { 99 logger.info(" No active system to minimize."); 100 return null; 101 } else { 102 Minimize minimize = new Minimize(assembly, null); 103 return minimize.minimize(eps); 104 } 105 } 106 107 /** 108 * {@inheritDoc} 109 * 110 * <p>Logs time since this interface was created and the last time this method was called. May be 111 * more elegant to replace this by using protected variables and simply inheriting the time() 112 * function. 113 */ 114 @Override 115 public double time() { 116 long currTime = System.nanoTime(); 117 logger.info( 118 String.format(" Time since interface established: %f", (currTime - initTime) * 1.0E-9)); 119 double elapsed = (currTime - interTime) * 1.0E-9; 120 interTime = currTime; 121 logger.info(String.format(" Time since last timer call: %f", elapsed)); 122 return elapsed; 123 } 124 }