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.potential.terms; 39 40 import ffx.potential.bonded.AngleTorsion; 41 import ffx.potential.bonded.BondedTerm; 42 43 import java.util.ArrayList; 44 import java.util.Collection; 45 import java.util.Collections; 46 import java.util.List; 47 import java.util.logging.Logger; 48 import static java.lang.String.format; 49 50 /** 51 * Angle-Torsion potential energy term using {@link ffx.potential.bonded.AngleTorsion} instances. 52 */ 53 public class AngleTorsionPotentialEnergy extends EnergyTerm { 54 55 private static final Logger logger = Logger.getLogger(AngleTorsionPotentialEnergy.class.getName()); 56 57 58 /** 59 * Internal list of AngleTorsion instances. 60 */ 61 private final List<AngleTorsion> angleTorsions = new ArrayList<>(); 62 63 /** 64 * Create an AngleTorsionPotentialEnergy with the provided name. 65 * 66 * @param name Name for this term. 67 */ 68 public AngleTorsionPotentialEnergy(String name) { 69 super(name); 70 } 71 72 /** 73 * Create an AngleTorsionPotentialEnergy with the provided name and force group. 74 * 75 * @param name Name for this term. 76 * @param forceGroup Integer force group identifier. 77 */ 78 public AngleTorsionPotentialEnergy(String name, int forceGroup) { 79 super(name, forceGroup); 80 } 81 82 /** 83 * Create an AngleTorsionPotentialEnergy initialized with a list of terms and force group. 84 * 85 * @param name Name for this term. 86 * @param forceGroup Force group identifier. 87 * @param angleTorsions List of AngleTorsion instances to add (null-safe). 88 */ 89 public AngleTorsionPotentialEnergy(String name, int forceGroup, List<AngleTorsion> angleTorsions) { 90 super(name, forceGroup); 91 if (angleTorsions != null) { 92 Collections.sort(angleTorsions); 93 this.angleTorsions.addAll(angleTorsions); 94 logger.info(format(" Angle-Torsions: %10d", getNumberOfAngleTorsions())); 95 } 96 } 97 98 /** 99 * {@inheritDoc} 100 */ 101 @Override 102 public int getNumberOfTerms() { 103 return getNumberOfAngleTorsions(); 104 } 105 106 /** 107 * {@inheritDoc} 108 */ 109 @Override 110 public BondedTerm[] getBondedTermsArray() { 111 return getAngleTorsionArray(); 112 } 113 114 /** 115 * Create an AngleTorsionPotentialEnergy initialized with a collection of terms. 116 * 117 * @param name Name for this term (may be null). 118 * @param angleTorsions Collection of AngleTorsion instances to add (null-safe). 119 */ 120 public AngleTorsionPotentialEnergy(String name, Collection<AngleTorsion> angleTorsions) { 121 super(name); 122 if (angleTorsions != null) { 123 this.angleTorsions.addAll(angleTorsions); 124 } 125 } 126 127 /** 128 * Add an AngleTorsion to this term. 129 * 130 * @param angleTorsion AngleTorsion to add (ignored if null). 131 * @return true if it was added. 132 */ 133 public boolean addAngleTorsion(AngleTorsion angleTorsion) { 134 if (angleTorsion == null) { 135 return false; 136 } 137 return angleTorsions.add(angleTorsion); 138 } 139 140 /** 141 * Add an array of AngleTorsions to this term. 142 * 143 * @param angleTorsions Array of AngleTorsion instances to add. 144 * @return true if they were added. 145 */ 146 public boolean addAngleTorsions(AngleTorsion[] angleTorsions) { 147 if (angleTorsions == null) { 148 return false; 149 } 150 Collections.addAll(this.angleTorsions, angleTorsions); 151 return true; 152 } 153 154 /** 155 * Add a list of AngleTorsions to this term. 156 * 157 * @param angleTorsions List of AngleTorsion instances to add. 158 * @return true if they were added. 159 */ 160 public boolean addAngleTorsions(List<AngleTorsion> angleTorsions) { 161 if (angleTorsions == null) { 162 return false; 163 } 164 this.angleTorsions.addAll(angleTorsions); 165 return true; 166 } 167 168 /** 169 * Remove an AngleTorsion from this term. 170 * 171 * @param angleTorsion AngleTorsion to remove (ignored if null). 172 * @return true if it was present and removed. 173 */ 174 public boolean removeAngleTorsion(AngleTorsion angleTorsion) { 175 if (angleTorsion == null) { 176 return false; 177 } 178 return angleTorsions.remove(angleTorsion); 179 } 180 181 /** 182 * Get the AngleTorsion at a given index. 183 * 184 * @param index Index in the internal list. 185 * @return AngleTorsion at the specified index. 186 * @throws IndexOutOfBoundsException if index is invalid. 187 */ 188 public AngleTorsion getAngleTorsion(int index) { 189 return angleTorsions.get(index); 190 } 191 192 /** 193 * Get an unmodifiable view of the AngleTorsions in this term. 194 * 195 * @return Unmodifiable List of AngleTorsions. 196 */ 197 public List<AngleTorsion> getAngleTorsions() { 198 return Collections.unmodifiableList(angleTorsions); 199 } 200 201 /** 202 * Get an array of AngleTorsions in this term. 203 * 204 * @return Array of AngleTorsions. 205 */ 206 public AngleTorsion[] getAngleTorsionArray() { 207 return angleTorsions.toArray(new AngleTorsion[0]); 208 } 209 210 /** 211 * Get the number of AngleTorsions in this term. 212 * 213 * @return The number of AngleTorsions. 214 */ 215 public int getNumberOfAngleTorsions() { 216 return angleTorsions.size(); 217 } 218 219 /** 220 * Log the details of Angle-Torsion interactions. 221 */ 222 @Override 223 public void log() { 224 if (getNumberOfAngleTorsions() <= 0) { 225 return; 226 } 227 logger.info("\n Angle-Torsion Interactions:"); 228 for (AngleTorsion angleTorsion : getAngleTorsions()) { 229 logger.info(" Angle-Torsion \t" + angleTorsion.toString()); 230 } 231 } 232 233 @Override 234 public String toPDBString() { 235 if (getNumberOfAngleTorsions() <= 0) { 236 return ""; 237 } 238 return format("REMARK 3 %s %g (%d)\n", "ANGLE-TORSION : ", getEnergy(), getNumberOfAngleTorsions()); 239 } 240 241 @Override 242 public String toString() { 243 return format(" %s %20.8f %12d %12.3f\n", "Angle-Torsion ", 244 getEnergy(), getNumberOfAngleTorsions(), getTime()); 245 } 246 }