clipper_cctbx.h

Go to the documentation of this file.
00001 
00004 //C Copyright (C) 2000-2006 Kevin Cowtan and University of York
00005 //L
00006 //L  This library is free software and is distributed under the terms
00007 //L  and conditions of version 2.1 of the GNU Lesser General Public
00008 //L  Licence (LGPL) with the following additional clause:
00009 //L
00010 //L     `You may also combine or link a "work that uses the Library" to
00011 //L     produce a work containing portions of the Library, and distribute
00012 //L     that work under terms of your choice, provided that you give
00013 //L     prominent notice with each copy of the work that the specified
00014 //L     version of the Library is used in it, and that you include or
00015 //L     provide public access to the complete corresponding
00016 //L     machine-readable source code for the Library including whatever
00017 //L     changes were used in the work. (i.e. If you make changes to the
00018 //L     Library you must distribute those, but you do not need to
00019 //L     distribute source or object code to those portions of the work
00020 //L     not covered by this licence.)'
00021 //L
00022 //L  Note that this clause grants an additional right and does not impose
00023 //L  any additional restriction, and so does not affect compatibility
00024 //L  with the GNU General Public Licence (GPL). If you wish to negotiate
00025 //L  other terms, please contact the maintainer.
00026 //L
00027 //L  You can redistribute it and/or modify the library under the terms of
00028 //L  the GNU Lesser General Public License as published by the Free Software
00029 //L  Foundation; either version 2.1 of the License, or (at your option) any
00030 //L  later version.
00031 //L
00032 //L  This library is distributed in the hope that it will be useful, but
00033 //L  WITHOUT ANY WARRANTY; without even the implied warranty of
00034 //L  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035 //L  Lesser General Public License for more details.
00036 //L
00037 //L  You should have received a copy of the CCP4 licence and/or GNU
00038 //L  Lesser General Public License along with this library; if not, write
00039 //L  to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040 //L  The GNU Lesser General Public can also be obtained by writing to the
00041 //L  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042 //L  MA 02111-1307 USA
00043 
00044 
00045 #ifndef CLIPPER_CCTBX
00046 #define CLIPPER_CCTBX
00047 
00048 
00049 #include "../core/hkl_datatypes.h"
00050 
00051 #include <cctbx/sgtbx/space_group.h>
00052 #include <cctbx/hendrickson_lattman.h>
00053 
00054 
00055 namespace clipper
00056 {
00057   namespace af = scitbx::af;
00058 
00060 
00063   class CCTBX
00064   {
00065   public:
00067     static cctbx::miller::index<> Hkl( const HKL& hkl );
00069     static HKL Hkl( const cctbx::miller::index<>& hkl );
00071 
00074     static inline const cctbx::miller::index<>& hkl( const HKL& hkl )
00075       { return reinterpret_cast<const cctbx::miller::index<>&>(hkl); }
00077 
00080     static inline const HKL& hkl( const cctbx::miller::index<>& hkl )
00081       { return reinterpret_cast<const HKL&>(hkl); }
00082 
00084     static cctbx::uctbx::unit_cell cell( const Cell& cell );
00086     static Cell cell( const cctbx::uctbx::unit_cell& cell );
00087 
00089     static cctbx::sgtbx::space_group spacegroup( const Spacegroup& spgr );
00091     static Spacegroup spacegroup( const cctbx::sgtbx::space_group& spgr );
00092 
00094     static HKL_info
00095     as_HKL_info(
00096       cctbx::uctbx::unit_cell const& unit_cell,
00097       cctbx::sgtbx::space_group const& space_group,
00098       double d_min,
00099       double tolerance=1.e-8)
00100     {
00101       return HKL_info(
00102         spacegroup(space_group),
00103         cell(unit_cell),
00104         Resolution(d_min-tolerance));
00105     }
00106 
00108     static HKL_info
00109     as_HKL_info(
00110       cctbx::uctbx::unit_cell const& unit_cell,
00111       cctbx::sgtbx::space_group const& space_group,
00112       af::const_ref<cctbx::miller::index<> > const& miller_indices,
00113       double tolerance=1.e-8)
00114     {
00115       double max_d_star_sq = unit_cell.max_d_star_sq(miller_indices);
00116       CCTBX_ASSERT(max_d_star_sq != 0);
00117       HKL_info result = as_HKL_info(
00118         unit_cell, space_group, 1/std::sqrt(max_d_star_sq), tolerance);
00119       std::vector<HKL> hkl_list;
00120       hkl_list.reserve(miller_indices.size());
00121       for(std::size_t i=0;i<miller_indices.size();i++) {
00122         hkl_list.push_back(Hkl(miller_indices[i]));
00123       }
00124       result.add_hkl_list(hkl_list);
00125       return result;
00126     }
00127 
00129     static HKL_data<data64::F_sigF>
00130     as_HKL_data(
00131       HKL_info& hkl_info,
00132       af::const_ref<cctbx::miller::index<> > const& miller_indices,
00133       af::const_ref<double> const& data,
00134       af::const_ref<double> const& sigmas)
00135     {
00136       CCTBX_ASSERT(data.size() == miller_indices.size());
00137       CCTBX_ASSERT(sigmas.size() == miller_indices.size());
00138       HKL_data<data64::F_sigF> hkl_data(hkl_info);
00139       for(std::size_t i=0;i<miller_indices.size();i++) {
00140         data64::F_sigF datum;
00141         datum.f() = data[i];
00142         datum.sigf() = sigmas[i];
00143         CCTBX_ASSERT(
00144           hkl_data.set_data(Hkl(miller_indices[i]), datum));
00145       }
00146       return hkl_data;
00147     }
00148 
00150     static HKL_data<data64::F_phi>
00151     as_HKL_data(
00152       HKL_info& hkl_info,
00153       af::const_ref<cctbx::miller::index<> > const& miller_indices,
00154       af::const_ref<std::complex<double> > const& data)
00155     {
00156       CCTBX_ASSERT(data.size() == miller_indices.size());
00157       HKL_data<data64::F_phi> hkl_data(hkl_info);
00158       for(std::size_t i=0;i<miller_indices.size();i++) {
00159         CCTBX_ASSERT(
00160           hkl_data.set_data(Hkl(miller_indices[i]), data64::F_phi(data[i])));
00161       }
00162       return hkl_data;
00163     }
00164 
00166     static af::shared<std::complex<double> >
00167     extract_complex(
00168       HKL_data<data64::F_phi> const& hkl_data,
00169       af::const_ref<cctbx::miller::index<> > const& miller_indices)
00170     {
00171       af::shared<std::complex<double> >
00172         result((af::reserve(miller_indices.size())));
00173       data64::F_phi datum;
00174       for(std::size_t i=0;i<miller_indices.size();i++) {
00175         CCTBX_ASSERT(hkl_data.get_data(CCTBX::Hkl(miller_indices[i]), datum));
00176         CCTBX_ASSERT(!datum.missing());
00177         result.push_back(datum);
00178       }
00179       return result;
00180     }
00181 
00183     static HKL_data<data64::ABCD>
00184     as_HKL_data(
00185       HKL_info& hkl_info,
00186       af::const_ref<cctbx::miller::index<> > const& miller_indices,
00187       af::const_ref<cctbx::hendrickson_lattman<> > const& data)
00188     {
00189       CCTBX_ASSERT(data.size() == miller_indices.size());
00190       HKL_data<data64::ABCD> hkl_data(hkl_info);
00191       data64::ABCD abcd;
00192       for(std::size_t i=0;i<miller_indices.size();i++) {
00193         abcd.data_import(data[i].begin());
00194         CCTBX_ASSERT(hkl_data.set_data(Hkl(miller_indices[i]), abcd));
00195       }
00196       return hkl_data;
00197     }
00198 
00200     static af::shared<cctbx::hendrickson_lattman<> >
00201     extract_hendrickson_lattman(
00202       HKL_data<data64::ABCD> const& hkl_data,
00203       af::const_ref<cctbx::miller::index<> > const& miller_indices)
00204     {
00205       af::shared<cctbx::hendrickson_lattman<> >
00206         result((af::reserve(miller_indices.size())));
00207       data64::ABCD datum;
00208       for(std::size_t i=0;i<miller_indices.size();i++) {
00209         CCTBX_ASSERT(hkl_data.get_data(CCTBX::Hkl(miller_indices[i]), datum));
00210         CCTBX_ASSERT(!datum.missing());
00211         result.push_back(cctbx::hendrickson_lattman<>(
00212           datum.a(), datum.b(), datum.c(), datum.d()));
00213       }
00214       return result;
00215     }
00216 
00218     static af::shared<double>
00219     extract_centroid_phases(
00220       HKL_data<data64::Phi_fom> const& hkl_data,
00221       af::const_ref<cctbx::miller::index<> > const& miller_indices)
00222     {
00223       af::shared<double>
00224         result((af::reserve(miller_indices.size())));
00225       data64::Phi_fom datum;
00226       for(std::size_t i=0;i<miller_indices.size();i++) {
00227         CCTBX_ASSERT(hkl_data.get_data(CCTBX::Hkl(miller_indices[i]), datum));
00228         CCTBX_ASSERT(!datum.missing());
00229         result.push_back(datum.phi());
00230       }
00231       return result;
00232     }
00233 
00235     static af::shared<double>
00236     extract_figures_of_merit(
00237       HKL_data<data64::Phi_fom> const& hkl_data,
00238       af::const_ref<cctbx::miller::index<> > const& miller_indices)
00239     {
00240       af::shared<double>
00241         result((af::reserve(miller_indices.size())));
00242       data64::Phi_fom datum;
00243       for(std::size_t i=0;i<miller_indices.size();i++) {
00244         CCTBX_ASSERT(hkl_data.get_data(CCTBX::Hkl(miller_indices[i]), datum));
00245         CCTBX_ASSERT(!datum.missing());
00246         result.push_back(datum.fom());
00247       }
00248       return result;
00249     }
00250   };
00251 
00252 } // namespace clipper
00253 
00254 #endif

Generated on 4 Jan 2010 for Clipper_cctbx by  doxygen 1.6.1