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-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.xray.commands;
39  
40  import ffx.algorithms.cli.AlgorithmsCommand;
41  import ffx.numerics.Potential;
42  import ffx.potential.MolecularAssembly;
43  import ffx.potential.bonded.Atom;
44  import ffx.potential.bonded.MSNode;
45  import ffx.potential.bonded.Molecule;
46  import ffx.utilities.FFXBinding;
47  import picocli.CommandLine.Command;
48  import picocli.CommandLine.Parameters;
49  
50  import java.io.File;
51  import java.util.Collections;
52  import java.util.List;
53  
54  import static org.apache.commons.io.FilenameUtils.removeExtension;
55  
56  /**
57   * Deuterate changes exchangeable hydrogen atoms to deuterium atoms for a PDB file.
58   * <br>
59   * Usage:
60   * <br>
61   * ffxc xray.Deuterate &lt;pdbfile1&gt;
62   */
63  @Command(description = " Deuterate exchangable hydrogen of the PDB model.", name = "xray.Deuterate")
64  public class Deuterate extends AlgorithmsCommand {
65  
66    /**
67     * One or more filenames.
68     */
69    @Parameters(arity = "1..*", paramLabel = "files", description = "PDB input file.")
70    private List<String> filenames;
71  
72    /**
73     * Deuterate constructor.
74     */
75    public Deuterate() {
76      super();
77    }
78  
79    /**
80     * Deuterate constructor that sets the command line arguments.
81     * @param args Command line arguments.
82     */
83    public Deuterate(String[] args) {
84      super(args);
85    }
86  
87    /**
88     * Deuterate constructor.
89     * @param binding The Binding to use.
90     */
91    public Deuterate(FFXBinding binding) {
92      super(binding);
93    }
94  
95    /**
96     * Execute the script.
97     */
98    @Override
99    public Deuterate run() {
100 
101     if (!init()) {
102       return this;
103     }
104 
105     MolecularAssembly[] molecularAssemblies;
106     String filename;
107     if (filenames != null && !filenames.isEmpty()) {
108       molecularAssemblies = algorithmFunctions.openAll(filenames.get(0));
109       activeAssembly = molecularAssemblies[0];
110       filename = filenames.get(0);
111     } else if (activeAssembly == null) {
112       logger.info(helpString());
113       return this;
114     } else {
115       molecularAssemblies = new MolecularAssembly[]{activeAssembly};
116       filename = activeAssembly.getFile().getAbsolutePath();
117     }
118 
119     logger.info("\n Running xray.Deuterate on " + filename);
120 
121     for (int i = 0; i < molecularAssemblies.length; i++) {
122       Atom[] atoms = molecularAssemblies[i].getAtomArray();
123       for (Atom a : atoms) {
124         if (a.getAtomicNumber() == 1) {
125           Atom b = a.getBonds().get(0).get1_2(a);
126 
127           // Criteria for converting H to D
128           if (b.getAtomicNumber() == 7
129               || b.getAtomicNumber() == 8) {
130             String name = a.getName().replaceFirst("H", "D");
131             a.setName(name);
132           }
133         }
134       }
135 
136       List<MSNode> water = molecularAssemblies[i].getWater();
137       for (MSNode node : water) {
138         Molecule wat = (Molecule) node;
139         wat.setName("DOD");
140       }
141     }
142 
143     algorithmFunctions.saveAsPDB(molecularAssemblies, new File(removeExtension(filename) + "_deuterate.pdb"));
144 
145     return this;
146   }
147 
148   @Override
149   public List<Potential> getPotentials() {
150     return Collections.emptyList();
151   }
152 }