Xmipp  v3.23.11-Nereus
pdb_nma_deform.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors:
4  *
5  * Carlos Oscar S. Sorzano (coss@cnb.csic.es)
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #include <fstream>
28 #include "pdb_nma_deform.h"
29 #include "core/metadata_vec.h"
30 #include "data/pdb.h"
31 
33 {
34  addUsageLine("Deform a PDB according to a list of NMA modes");
35  addUsageLine("+It is assumed that there is a deformation value per mode, and that the number of vectors in the mode is the same as the number of atoms in the PDB");
36  addParamsLine("--pdb <file> : PDB to deform");
37  addParamsLine("--nma <metadata_file> : List of modes, the metadata must use the label NMAModefile");
38  addParamsLine("--deformations <...> : Deformation amplitudes in each direction");
39  addParamsLine("-o <file> : Deformed PDB");
40  addExampleLine("xmipp_pdb_nma_deform --pdb 2tbv.pdb -o 2tbv_deformed.pdb --nma modelist.xmd --deformations 15");
41 }
42 
44 {
45  fn_pdb=getParam("--pdb");
46  fn_nma=getParam("--nma");
47  fn_out=getParam("-o");
48  StringVector listDeformations;
49  getListParam("--deformations",listDeformations);
50  deformations.resizeNoCopy(listDeformations.size());
52  deformations(i)=textToFloat(listDeformations[i]);
53 }
54 
56 {
57  if (verbose==0)
58  return;
59  std::cout
60  << "PDB: " << fn_pdb << std::endl
61  << "NMA list: " << fn_nma << std::endl
62  << "Output: " << fn_out << std::endl
63  << "Deformations: "
64  ;
66  std::cout << deformations(i) << " ";
67  std::cout << std::endl;
68 }
69 
71 {
72  PDBRichPhantom pdb;
73  MetaDataVec modes;
74  pdb.read(fn_pdb);
75  modes.read(fn_nma);
76  modes.removeDisabled();
77  int j=0;
78  FileName fnMode;
80  mode.resizeNoCopy(pdb.getNumberOfAtoms(),3);
81 
82  for (size_t objId : modes.ids())
83  {
84  // Read mode
85  modes.getValue(MDL_NMA_MODEFILE,fnMode,objId);
86  std::ifstream fhMode;
87  fhMode.open(fnMode.c_str());
88  if (!fhMode)
90  fhMode >> mode;
91  fhMode.close();
92 
93  // Apply mode
94  double lambda=A1D_ELEM(deformations,j);
95  for (size_t i=0; i<YSIZE(mode); ++i)
96  {
97  RichAtom& atom_i=pdb.atomList[i];
98  atom_i.x+=lambda*DIRECT_A2D_ELEM(mode,i,0);
99  atom_i.y+=lambda*DIRECT_A2D_ELEM(mode,i,1);
100  atom_i.z+=lambda*DIRECT_A2D_ELEM(mode,i,2);
101  }
102  j++;
103  }
104  pdb.write(fn_out);
105 }
#define YSIZE(v)
void read(const FileName &fnPDB, const bool pseudoatoms=false, const double threshold=0.0)
Read rich phantom from either a PDB of CIF file.
Definition: pdb.cpp:704
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void write(const FileName &fnPDB, const bool renumber=false)
Write rich phantom to PDB or CIF file.
Definition: pdb.cpp:872
void resizeNoCopy(const MultidimArray< T1 > &v)
#define DIRECT_A2D_ELEM(v, i, j)
#define A1D_ELEM(v, i)
Definition: pdb.h:174
void getListParam(const char *param, StringVector &list)
virtual IdIteratorProxy< false > ids()
std::vector< String > StringVector
Definition: xmipp_strings.h:35
#define i
const char * getParam(const char *param, int arg=0)
double y
Position Y.
Definition: pdb.h:187
double * lambda
float textToFloat(const char *str)
void addExampleLine(const char *example, bool verbatim=true)
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
int verbose
Verbosity level.
void mode
double x
Position X.
Definition: pdb.h:184
#define j
bool getValue(MDObject &mdValueOut, size_t id) const override
std::vector< RichAtom > atomList
List of atoms.
Definition: pdb.h:257
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
size_t getNumberOfAtoms() const
Get number of atoms.
Definition: pdb.h:270
virtual void removeDisabled()
void addUsageLine(const char *line, bool verbatim=false)
MultidimArray< double > deformations
File with an NMA mode.
void addParamsLine(const String &line)
double z
Position Z.
Definition: pdb.h:190