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.commands;
39
40 import ffx.potential.MolecularAssembly;
41 import ffx.potential.Utilities.FileType;
42 import ffx.potential.bonded.Atom;
43 import ffx.potential.bonded.Bond;
44 import ffx.potential.parameters.AtomType;
45 import ffx.potential.parsers.SystemFilter;
46 import java.io.File;
47 import java.util.ArrayList;
48 import java.util.Hashtable;
49 import java.util.Vector;
50
51 /**
52 * The SimulationFilter class parses system data sent by FFXServer to FFXClient.
53 *
54 * @author Michael J. Schnieders
55 */
56 public final class SimulationFilter extends SystemFilter {
57
58 SimulationDefinition system;
59 Hashtable<Integer, AtomType> atomTypes = new Hashtable<Integer, AtomType>();
60
61 /**
62 * Constructor for SimulationFilter.
63 *
64 * @param sys a {@link ffx.ui.commands.SimulationDefinition} object.
65 * @param m a {@link ffx.potential.MolecularAssembly} object.
66 */
67 public SimulationFilter(SimulationDefinition sys, MolecularAssembly m) {
68 super(new File(""), m, null, null);
69 system = sys;
70 fileType = FileType.SIM;
71 fileRead = false;
72 }
73
74 @Override
75 public void closeReader() {
76 // logger.fine(" Reading trajectories not yet supported for MergeFilter");
77 // No logger set for SimulationFilter.
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public boolean readFile() {
83 // Create Molecular Mechanics Data Objects from the SimulationDefinition
84 // information
85 for (int i = 0; i < system.numatoms; i++) {
86 AtomType atomType = atomTypes.get(system.types[i]);
87 if (atomType == null) {
88 atomType =
89 new AtomType(
90 system.types[i],
91 -1,
92 system.name[i],
93 system.story[i],
94 system.atomic[i],
95 system.mass[i],
96 0);
97 atomTypes.put(system.types[i], atomType);
98 }
99 }
100 atomList = new ArrayList<Atom>();
101 Vector<Integer> bonds1 = new Vector<Integer>();
102 Vector<Integer> bonds2 = new Vector<Integer>();
103 double[] d = new double[3];
104 int[] b = new int[4];
105 for (int i = 0; i < system.numatoms; i++) {
106 d[0] = system.coordinates[0][i];
107 d[1] = system.coordinates[1][i];
108 d[2] = system.coordinates[2][i];
109 String s = "" + system.types[i];
110 AtomType atomType = atomTypes.get(s);
111 Atom a = new Atom(i + 1, "" + atomType.type, atomType, d);
112 atomList.add(a);
113 int b1 = i + 1;
114 b[0] = system.connectivity[0][i];
115 b[1] = system.connectivity[1][i];
116 b[2] = system.connectivity[2][i];
117 b[3] = system.connectivity[3][i];
118 int j = 0;
119 while (j < 4 && b[j] != 0) {
120 int b2 = b[j];
121 bonds1.add(b1);
122 bonds2.add(b2);
123 j++;
124 }
125 }
126 bondList = new ArrayList<Bond>();
127 for (int i = 0; i < bonds1.size(); i++) {
128 int a1 = bonds1.get(i);
129 int a2 = bonds2.get(i);
130 if (a1 < a2) {
131 Atom atom1 = atomList.get(a1 - 1);
132 Atom atom2 = atomList.get(a2 - 1);
133 bondList.add(new Bond(atom1, atom2));
134 }
135 }
136 setFileRead(true);
137 return true;
138 }
139
140 @Override
141 public boolean readNext(boolean resetPosition) {
142 return false;
143 }
144
145 @Override
146 public boolean readNext(boolean resetPosition, boolean print) {
147 return false;
148 }
149
150 @Override
151 public boolean readNext(boolean resetPosition, boolean print, boolean parse) {
152 return false;
153 }
154
155 @Override
156 public boolean readNext() {
157 return readNext(false);
158 }
159
160 /** {@inheritDoc} */
161 @Override
162 public boolean writeFile(File saveFile, boolean append, String[] extraLines) {
163 return false;
164 }
165 }