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