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.ui;
39
40 import ffx.potential.MolecularAssembly;
41 import ffx.potential.bonded.Atom;
42 import ffx.utilities.Keyword;
43 import java.io.File;
44 import java.io.Serial;
45 import java.util.Hashtable;
46 import org.apache.commons.configuration2.CompositeConfiguration;
47 import org.apache.commons.io.FilenameUtils;
48
49 /**
50 * The FFXSystem class contains extensions to the generic MolecularAssembly class.
51 *
52 * @author Michael J. Schnieders
53 */
54 public class FFXSystem extends MolecularAssembly {
55
56 @Serial
57 private static final long serialVersionUID = 1L;
58
59 /** Constant <code>MultiScaleLevel=4</code> */
60 public static final int MultiScaleLevel = 4;
61 // Log file being used for modeling commands
62 private File logFile;
63 // Key file for this system
64 private File keyFile;
65 private Hashtable<String, Keyword> keywords = new Hashtable<String, Keyword>();
66 private final CompositeConfiguration properties;
67 private String commandDescription;
68 // Archive
69 private Trajectory trajectory = null;
70 // Flag to indicate this System is being closed
71 private boolean closing = false;
72
73 /**
74 * Constructor.
75 *
76 * @param file Coordinate file.
77 * @param description Short description of the command that created this system.
78 * @param properties Properties controlling operations on this system.
79 */
80 public FFXSystem(File file, String description, CompositeConfiguration properties) {
81 super(FilenameUtils.getBaseName(file.getName()));
82 setFile(file);
83 commandDescription = description;
84 this.properties = properties;
85 }
86
87 /**
88 * addKeyword
89 *
90 * @param k a {@link ffx.utilities.Keyword} object.
91 */
92 public void addKeyword(Keyword k) {
93 if (keywords.containsKey(k.getKeyword())) {
94 return;
95 }
96 keywords.put(k.getKeyword(), k);
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public boolean destroy() {
102 setClosing(true);
103 return super.destroy();
104 }
105
106 /**
107 * Getter for the field <code>keyFile</code>.
108 *
109 * @return a {@link java.io.File} object.
110 */
111 public File getKeyFile() {
112 return keyFile;
113 }
114
115 /**
116 * Setter for the field <code>keyFile</code>.
117 *
118 * @param f a {@link java.io.File} object.
119 */
120 public void setKeyFile(File f) {
121 keyFile = f;
122 }
123
124 /**
125 * getKeyword
126 *
127 * @param k a {@link java.lang.String} object.
128 * @return a {@link ffx.utilities.Keyword} object.
129 */
130 public Keyword getKeyword(String k) {
131 return keywords.get(k);
132 }
133
134 /**
135 * Getter for the field <code>keywords</code>.
136 *
137 * @return a {@link java.util.Hashtable} object.
138 */
139 public Hashtable<String, Keyword> getKeywords() {
140 return keywords;
141 }
142
143 /**
144 * Setter for the field <code>keywords</code>.
145 *
146 * @param k a {@link java.util.Hashtable} object.
147 */
148 public void setKeywords(Hashtable<String, Keyword> k) {
149 keywords = k;
150 }
151
152 /**
153 * Getter for the field <code>logFile</code>.
154 *
155 * @return a {@link java.io.File} object.
156 */
157 public File getLogFile() {
158 if (logFile == null) {
159 if (getFile() == null) {
160 return null;
161 }
162 String fileName = getFile().getName();
163 int dot = fileName.lastIndexOf(".");
164 fileName = fileName.subSequence(0, dot) + ".log";
165 logFile = new File(fileName);
166 }
167 return logFile;
168 }
169
170 /**
171 * Setter for the field <code>logFile</code>.
172 *
173 * @param f a {@link java.io.File} object.
174 */
175 public void setLogFile(File f) {
176 logFile = f;
177 }
178
179 /**
180 * Getter for the field <code>properties</code>.
181 *
182 * @return a {@link org.apache.commons.configuration2.CompositeConfiguration} object.
183 */
184 @Override
185 public CompositeConfiguration getProperties() {
186 return properties;
187 }
188
189 /**
190 * Getter for the field <code>trajectory</code>.
191 *
192 * @return a {@link ffx.ui.Trajectory} object.
193 */
194 public Trajectory getTrajectory() {
195 return trajectory;
196 }
197
198 /**
199 * Setter for the field <code>trajectory</code>.
200 *
201 * @param t a {@link ffx.ui.Trajectory} object.
202 */
203 public void setTrajectory(Trajectory t) {
204 trajectory = t;
205 }
206
207 /**
208 * isClosing
209 *
210 * @return a boolean.
211 */
212 public boolean isClosing() {
213 return closing;
214 }
215
216 /**
217 * Setter for the field <code>closing</code>.
218 *
219 * @param b a boolean.
220 */
221 public void setClosing(boolean b) {
222 closing = b;
223 }
224
225 /**
226 * isStale
227 *
228 * @return a boolean.
229 */
230 public boolean isStale() {
231 for (Atom a : getAtomList()) {
232 if (a.isStale()) {
233 return true;
234 }
235 }
236 return false;
237 }
238
239 /**
240 * removeKeyword
241 *
242 * @param kd a {@link ffx.utilities.Keyword} object.
243 */
244 public void removeKeyword(Keyword kd) {
245 if (keywords.containsKey(kd.getKeyword())) {
246 keywords.remove(kd.getKeyword());
247 }
248 }
249
250 /**
251 * Setter for the field <code>commandDescription</code>.
252 *
253 * @param command a {@link java.lang.String} object.
254 */
255 public void setCommandDescription(String command) {
256 commandDescription = command;
257 }
258
259 /**
260 * toFFString
261 *
262 * @return a {@link java.lang.String} object.
263 */
264 public String toFFString() {
265 StringBuilder sb = new StringBuilder(toString());
266 if (forceField != null) {
267 String ff = forceField.toString("forcefield");
268 if (ff != null) {
269 ff = ff.substring(10).trim();
270 sb.append(" (");
271 sb.append(ff);
272 sb.append(")");
273 }
274 }
275 return sb.toString();
276 }
277
278 /**
279 * toFileString
280 *
281 * @return a {@link java.lang.String} object.
282 */
283 public String toFileString() {
284 if (getFile() == null) {
285 return toFFString();
286 }
287 StringBuilder sb = new StringBuilder(getFile().getAbsolutePath());
288 if (forceField != null) {
289 String ff = forceField.toString("forcefield");
290 if (ff != null) {
291 ff = ff.substring(10).trim();
292 sb.append(" (");
293 sb.append(ff);
294 sb.append(")");
295 }
296 }
297 return sb.toString();
298 }
299
300 /** {@inheritDoc} */
301 @Override
302 public String toString() {
303 if (getFile() != null) {
304 if (commandDescription != null) {
305 return getFile().getName() + " (" + commandDescription + ")";
306 }
307 return getFile().getName();
308 }
309 if (getName() != null) {
310 if (commandDescription != null) {
311 return getName() + commandDescription;
312 }
313 return getName();
314 }
315 return "FFX System";
316 }
317 }