1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 package ffx.potential.bonded;
39
40 import ffx.potential.parameters.ForceField;
41
42 import java.io.Serial;
43 import java.util.Objects;
44 import java.util.logging.Logger;
45
46
47
48
49
50
51
52
53 @SuppressWarnings("CloneableImplementsClone")
54 public class Molecule extends MSGroup {
55
56 @Serial
57 private static final long serialVersionUID = 1L;
58
59 private static final Logger logger = Logger.getLogger(Molecule.class.getName());
60
61
62 private int residueNum;
63
64 private String residueName;
65
66 private Character chainID;
67
68 private final String segID;
69
70
71
72
73
74
75 public Molecule(String name) {
76 super(name);
77 residueName = name;
78 residueNum = -1;
79 chainID = 'A';
80 segID = "A";
81 }
82
83
84
85
86
87
88
89
90
91 public Molecule(String name, int residueNum, Character chainID, String segID) {
92 super(name + "-" + residueNum + " " + segID);
93 this.residueName = name;
94 this.residueNum = residueNum;
95 this.chainID = chainID;
96 this.segID = segID;
97 }
98
99
100
101
102
103
104 public void setChainID(Character c) {
105 chainID = c;
106
107 for (Atom atom : getAtomList()) {
108 atom.setChainID(c);
109 }
110 }
111
112
113
114
115
116
117 public void setResidueNum(int residueNum) {
118 this.residueNum = residueNum;
119 for (Atom atom : getAtomList()) {
120 atom.setResidueNumber(residueNum);
121 }
122 }
123
124
125
126
127
128
129 @Override
130 public MSNode addMSNode(MSNode o) {
131 Atom currentAtom = null;
132 if (o instanceof Atom) {
133 Atom newAtom = (Atom) o;
134 Character newAlt = newAtom.getAltLoc();
135 MSNode atoms = getAtomNode();
136 currentAtom = (Atom) atoms.contains(newAtom);
137 if (currentAtom == null) {
138 currentAtom = newAtom;
139 atoms.add(newAtom);
140 setFinalized(false);
141 } else {
142
143 Character currentAlt = currentAtom.getAltLoc();
144 if (currentAlt.equals(' ') || currentAlt.equals('A')) {
145 if (!newAlt.equals(' ') && !newAlt.equals('A')) {
146 newAtom.setXyzIndex(currentAtom.getXyzIndex());
147 atoms.remove(currentAtom);
148 currentAtom = newAtom;
149 atoms.add(currentAtom);
150 setFinalized(false);
151 }
152 }
153 }
154 } else {
155 logger.warning(" Only an Atom can be added to a Residue.");
156 }
157 return currentAtom;
158 }
159
160 @Override
161 public boolean equals(Object o) {
162 if (this == o) {
163 return true;
164 }
165 if (o == null || getClass() != o.getClass()) {
166 return false;
167 }
168 Molecule molecule = (Molecule) o;
169 return residueNum == molecule.residueNum
170 && Objects.equals(residueName, molecule.residueName)
171 && Objects.equals(segID, molecule.segID);
172 }
173
174
175 @Override
176 public void finalize(boolean finalizeGeometry, ForceField forceField) {
177 setFinalized(false);
178 getAtomNode().setName("Atoms (" + getAtomList().size() + ")");
179 if (finalizeGeometry) {
180 assignBondedTerms(forceField);
181 removeLeaves();
182 }
183 setCenter(getMultiScaleCenter(false));
184 setFinalized(true);
185 }
186
187
188
189
190
191
192
193 public Atom getAtom(String name) {
194 for (Atom a : getAtomList()) {
195 if (a.getName().equalsIgnoreCase(name)) {
196 return a;
197 }
198 }
199 return null;
200 }
201
202
203
204
205
206
207 public Character getChainID() {
208 return chainID;
209 }
210
211 public String getKey() {
212 return residueNum + residueName + segID;
213 }
214
215
216
217
218
219
220 public String getResidueName() {
221 return residueName;
222 }
223
224
225
226
227
228
229 public int getResidueNumber() {
230 return residueNum;
231 }
232
233
234
235
236
237
238 public String getSegID() {
239 return segID;
240 }
241
242 @Override
243 public int hashCode() {
244 return Objects.hash(residueNum, residueName, segID);
245 }
246
247
248 @Override
249 public void setName(String name) {
250 if (name != null) {
251 if (segID != null) {
252 super.setName(name + "-" + residueNum + " " + segID);
253 } else {
254 super.setName(name);
255 }
256 this.residueName = name;
257 }
258 }
259 }