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.algorithms.mc;
39
40 import ffx.potential.bonded.AminoAcidUtils;
41 import ffx.potential.bonded.AminoAcidUtils.AminoAcid3;
42 import ffx.potential.bonded.Residue;
43 import ffx.potential.bonded.ResidueState;
44 import ffx.potential.bonded.Rotamer;
45 import ffx.potential.bonded.RotamerLibrary;
46 import ffx.potential.bonded.Torsion;
47
48 import java.util.concurrent.ThreadLocalRandom;
49
50 import static java.lang.String.format;
51
52 /**
53 * Represents a random chi[0] spin of the target residue. For use with RosenbluthRotamerMC.
54 *
55 * @author Stephen D. LuCore
56 */
57 public class RosenbluthChi0Move implements MCMove {
58
59 /** The value of theta. */
60 public final double theta;
61 /** The residue to operate on. */
62 private final Residue target;
63 /** The original residue state. */
64 private final ResidueState origState;
65 /** The rotamer to try. */
66 private final Rotamer newState;
67
68 /**
69 * Constructor for RosenbluthChi0Move.
70 *
71 * @param target a {@link ffx.potential.bonded.Residue} object.
72 */
73 RosenbluthChi0Move(Residue target) {
74 this.target = target;
75 AminoAcid3 name = AminoAcidUtils.AminoAcid3.valueOf(target.getName());
76 origState = target.storeState();
77 double[] chi = RotamerLibrary.measureRotamer(target, false);
78 theta = ThreadLocalRandom.current().nextDouble(360.0) - 180;
79 chi[0] = theta;
80
81 // Need to add sigma values to construct a new Rotamer with these chis.
82 double[] values = new double[chi.length * 2];
83 for (int i = 0; i < chi.length; i++) {
84 int ii = 2 * i;
85 values[ii] = chi[i];
86 values[ii + 1] = 0.0;
87 }
88
89 newState = new Rotamer(name, values);
90 }
91
92 /**
93 * {@inheritDoc}
94 *
95 * <p>Performs the move associated with this MCMove. Also updates chi values in associated Torsion
96 * objects.
97 */
98 @Override
99 public void move() {
100 RotamerLibrary.applyRotamer(target, newState);
101 updateTorsions();
102 }
103
104 /**
105 * {@inheritDoc}
106 *
107 * <p>Reverts the last applied move() call.
108 */
109 @Override
110 public void revertMove() {
111 target.revertState(origState);
112 updateTorsions();
113 }
114
115 /** {@inheritDoc} */
116 @Override
117 public String toString() {
118 return format("Rosenbluth Rotamer Move:\n Res: %s\n Theta: %3.2f", target.toString(),
119 theta);
120 }
121
122 /** Update all torsions. */
123 private void updateTorsions() {
124 for (Torsion torsion : target.getTorsionList()) {
125 torsion.update();
126 }
127 }
128 }