View Javadoc
1   package ffx.xray.refine;
2   
3   import java.util.logging.Logger;
4   
5   import static ffx.potential.parameters.ForceField.toEnumForm;
6   import static java.lang.String.format;
7   
8   /**
9    * Different refinement mode selection types.
10   */
11  public enum RefinementMode {
12  
13    /**
14     * refine B factors only (if anisotropic, refined as such)
15     */
16    BFACTORS,
17    /**
18     * refine B factors and occupancies
19     */
20    BFACTORS_AND_OCCUPANCIES,
21    /**
22     * refine coordinates only
23     */
24    COORDINATES,
25    /**
26     * refine coordinates and B factors (if anisotropic, refined as such)
27     */
28    COORDINATES_AND_BFACTORS,
29    /**
30     * refine all
31     */
32    COORDINATES_AND_BFACTORS_AND_OCCUPANCIES,
33    /**
34     * refine coordinates and occupancies
35     */
36    COORDINATES_AND_OCCUPANCIES,
37    /**
38     * refine occupancies only (alternate conformers are constrained)
39     */
40    OCCUPANCIES;
41  
42    /**
43     * Determines whether the refinement mode includes coordinates.
44     *
45     * @return true if the refinement mode involves coordinates, false otherwise.
46     */
47    public boolean includesCoordinates() {
48      return this == COORDINATES ||
49          this == COORDINATES_AND_BFACTORS ||
50          this == COORDINATES_AND_OCCUPANCIES ||
51          this == COORDINATES_AND_BFACTORS_AND_OCCUPANCIES;
52    }
53  
54    /**
55     * Determines whether the refinement mode includes B-factors.
56     *
57     * @return true if the refinement mode involves B-factors, false otherwise.
58     */
59    public boolean includesBFactors() {
60      return this == BFACTORS ||
61          this == BFACTORS_AND_OCCUPANCIES ||
62          this == COORDINATES_AND_BFACTORS ||
63          this == COORDINATES_AND_BFACTORS_AND_OCCUPANCIES;
64    }
65  
66    /**
67     * Determines whether the refinement mode includes occupancies.
68     *
69     * @return true if the refinement mode involves occupancies, false otherwise.
70     */
71    public boolean includesOccupancies() {
72      return this == OCCUPANCIES ||
73          this == BFACTORS_AND_OCCUPANCIES ||
74          this == COORDINATES_AND_OCCUPANCIES ||
75          this == COORDINATES_AND_BFACTORS_AND_OCCUPANCIES;
76    }
77  
78    public String toString() {
79      return switch (this) {
80        case BFACTORS -> " Mode: B-Factors";
81        case BFACTORS_AND_OCCUPANCIES -> " Mode: B-Factors and Occupancies";
82        case COORDINATES -> " Mode: Coordinates";
83        case COORDINATES_AND_BFACTORS -> " Mode: Coordinates and B-Factors";
84        case COORDINATES_AND_BFACTORS_AND_OCCUPANCIES -> " Mode: Coordinates, B-Factors and Occupancies";
85        case COORDINATES_AND_OCCUPANCIES -> " Mode: Coordinates and Occupancies";
86        case OCCUPANCIES -> " Mode: Occupancies";
87      };
88    }
89  
90    /**
91     * Returns the default epsilon value for the current refinement mode.
92     *
93     * @return The default epsilon value for the current refinement mode.
94     */
95    public double getDefaultEps() {
96      return getDefaultEps(false);
97    }
98  
99    /**
100    * Returns the default epsilon value for the current refinement mode.
101    * The returned value depends on whether the refinement mode includes anisotropic
102    * displacement parameters (ANISOU) and the specific refinement mode.
103    *
104    * @param hasAnisou Indicates whether the refinement mode includes anisotropic displacement parameters.
105    * @return The default epsilon value for the current refinement mode.
106    */
107   public double getDefaultEps(boolean hasAnisou) {
108     return switch (this) {
109       case BFACTORS, BFACTORS_AND_OCCUPANCIES -> {
110         if (hasAnisou) {
111           yield 20.0;
112         } else {
113           yield 0.01;
114         }
115       }
116       case COORDINATES -> 0.4;
117       case COORDINATES_AND_BFACTORS, COORDINATES_AND_BFACTORS_AND_OCCUPANCIES -> {
118         if (hasAnisou) {
119           yield 20.0;
120         } else {
121           yield 0.2;
122         }
123       }
124       case COORDINATES_AND_OCCUPANCIES -> 0.2;
125       case OCCUPANCIES -> 0.1;
126     };
127   }
128 
129   /**
130    * Parse a string into a refinement mode.
131    *
132    * @param mode Refinement mode string.
133    * @return An instance of RefinementMode.
134    */
135   public static RefinementMode parseMode(String mode) {
136     try {
137       return RefinementMode.valueOf(toEnumForm(mode));
138     } catch (Exception e) {
139       Logger logger = Logger.getLogger(RefinementMode.class.getName());
140       logger.info(format(" Could not parse %s as a refinement mode; defaulting to coordinates.", mode));
141       return RefinementMode.COORDINATES;
142     }
143   }
144 
145 }