MPQC  3.0.0-alpha
orbitalspace.timpl.h
1 //
2 // orbitalspace.timpl.h
3 //
4 // Copyright (C) 2009 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.edu>
7 // Maintainer: EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _mpqc_src_lib_chemistry_qc_mbptr12_orbitalspacetimpl_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_orbitalspacetimpl_h
30 
31 // includes go here
32 #include <chemistry/qc/wfn/orbitalspace.h>
33 #include <algorithm>
34 #include <cassert>
35 #include <vector>
36 
37 namespace sc {
38 
39  template <typename Order>
40  ClassDesc
41  OrderedOrbitalSpace<Order>::class_desc_(typeid(this_type),
42  (std::string("OrderedOrbitalSpace<") +
43  std::string(typeid(Order).name()) +
44  std::string(">")
45  ).c_str(), 1,
46  "public OrbitalSpace", 0, 0,
47  create<this_type> );
48 
49  template <typename Order>
50  OrderedOrbitalSpace<Order>::OrderedOrbitalSpace(StateIn& si) :
51  OrbitalSpace(si) {}
52 
53  template <typename Order>
54  void
57  }
58 
59  template <typename Order>
61  }
62 
63  template <typename Order>
64  OrderedOrbitalSpace<Order>::OrderedOrbitalSpace(const std::string& id,
65  const std::string& name,
66  const Ref<GaussianBasisSet>& basis,
67  const Ref<Integral>& integral,
68  const RefSCMatrix& coefs,
69  const RefDiagSCMatrix& evals,
70  const RefDiagSCMatrix& occnums,
71  const std::vector<unsigned int>& orbsyms,
72  const Order& order) :
73  OrbitalSpace() {
74 
75  // validate input
76  const size_t norbs = coefs.coldim().n();
77  if (orbsyms.empty() == false) {
78  const unsigned int max_orbsym = *(std::max_element(orbsyms.begin(), orbsyms.end()));
79  const unsigned int min_orbsym = *(std::min_element(orbsyms.begin(), orbsyms.end()));
80  const unsigned int nirreps = basis->molecule()->point_group()->char_table().order();
81  if (min_orbsym >= nirreps || max_orbsym >= nirreps)
82  throw ProgrammingError("OrderedOrbitalSpace -- invalid orbital symmetry array",__FILE__,__LINE__);
83  }
84 
85  // construct vector of MolecularOrbital objects
86  std::vector<MolecularOrbital> orbs;
87  for(size_t o=0; o<norbs; ++o) {
88  orbs.push_back(MolecularOrbital(o,
89  MolecularOrbitalAttributes(orbsyms.at(o),
90  evals.get_element(o),
91  occnums.get_element(o)
92  )
93  ));
94  }
95 
96  // sort
97  std::stable_sort(orbs.begin(), orbs.end(), order);
98 
99  // convert vector of MolecularOrbitals to BlockedOrbitals
100  std::vector<BlockedOrbital> blocked_orbs;
101  for(size_t o=0; o<norbs; ++o) {
102  blocked_orbs.push_back(BlockedOrbital(orbs[o].index(),
103  order.block(orbs[o])
104  ));
105  }
106 
107  init(id, name, basis, integral, coefs, evals, orbsyms, order.nblocks(), blocked_orbs);
108 
109  }
110 
112 
113  template <typename Order>
114  ClassDesc
115  OrderedSpinOrbitalSpace<Order>::class_desc_(typeid(this_type),
116  (std::string("OrderedSpinOrbitalSpace<") +
117  std::string(typeid(Order).name()) +
118  std::string(">")
119  ).c_str(), 1,
120  "public OrbitalSpace", 0, 0,
121  create<this_type> );
122 
123  template <typename Order>
124  OrderedSpinOrbitalSpace<Order>::OrderedSpinOrbitalSpace(StateIn& si) :
125  OrbitalSpace(si) {}
126 
127  template <typename Order>
128  void
131  }
132 
133  template <typename Order>
135  }
136 
137  template <typename Order>
138  OrderedSpinOrbitalSpace<Order>::OrderedSpinOrbitalSpace(const std::string& id,
139  const std::string& name,
140  const Ref<GaussianBasisSet>& basis,
141  const Ref<Integral>& integral,
142  const RefSCMatrix& coefs_a,
143  const RefSCMatrix& coefs_b,
144  const RefDiagSCMatrix& evals_a,
145  const RefDiagSCMatrix& evals_b,
146  const RefDiagSCMatrix& occnums_a,
147  const RefDiagSCMatrix& occnums_b,
148  const std::vector<unsigned int>& orbsyms_a,
149  const std::vector<unsigned int>& orbsyms_b,
150  const Order& order) :
151  OrbitalSpace() {
152 
153  // validate input
154  const size_t norbs = coefs_a.coldim().n();
155  MPQC_ASSERT(norbs != 0);
156  MPQC_ASSERT(norbs == coefs_b.coldim().n());
157  const unsigned int max_orbsym_a = *(std::max_element(orbsyms_a.begin(), orbsyms_a.end()));
158  const unsigned int min_orbsym_a = *(std::min_element(orbsyms_a.begin(), orbsyms_a.end()));
159  const unsigned int max_orbsym_b = *(std::max_element(orbsyms_b.begin(), orbsyms_b.end()));
160  const unsigned int min_orbsym_b = *(std::min_element(orbsyms_b.begin(), orbsyms_b.end()));
161  const unsigned int max_orbsym = std::max(max_orbsym_a,max_orbsym_b);
162  const unsigned int min_orbsym = std::min(min_orbsym_a,min_orbsym_b);
163  const unsigned int nirreps = basis->molecule()->point_group()->char_table().order();
164  if (min_orbsym >= nirreps || max_orbsym >= nirreps)
165  throw ProgrammingError("OrderedSpinOrbitalSpace -- invalid orbital symmetry arrays",__FILE__,__LINE__);
166 
168  // Merge alpha and beta orbitals:
170 
171  // 1) construct vector of MolecularOrbital objects
172  std::vector<MolecularSpinOrbital> orbs;
173  for(size_t o=0; o<norbs; ++o) { // alpha spin
174  orbs.push_back(MolecularSpinOrbital(o,
175  MolecularSpinOrbitalAttributes(orbsyms_a.at(o),
176  evals_a.get_element(o),
177  occnums_a.get_element(o),
178  Alpha
179  )
180  ));
181  }
182  for(size_t o=0; o<norbs; ++o) { // beta spin
183  orbs.push_back(MolecularSpinOrbital(o + norbs,
184  MolecularSpinOrbitalAttributes(orbsyms_b.at(o),
185  evals_b.get_element(o),
186  occnums_b.get_element(o),
187  Beta
188  )
189  ));
190  }
191 
192  // sort
193  std::stable_sort(orbs.begin(), orbs.end(), order);
194 
195  // convert vector of MolecularOrbitals to BlockedOrbitals
196  std::vector<BlockedOrbital> blocked_orbs;
197  for(size_t o=0; o<norbs*2; ++o) {
198  const unsigned index = orbs[o].index();
199  const unsigned block = order.block(orbs[o]);
200  BlockedOrbital orb(index,block);
201  blocked_orbs.push_back(orb);
202  }
203 
204  // 2) merge coefficients, eigenvalues, and occupations
205  RefSCDimension orbdim;
206  {
207  const unsigned int nblocks = coefs_a.coldim()->blocks()->nblock() * 2;
208  // build new blocked dimension
209  int* nfunc_per_block = new int[nblocks];
210  for (unsigned int i = 0; i < nblocks/2; ++i)
211  nfunc_per_block[i] = coefs_a.coldim()->blocks()->size(i);
212  for (unsigned int i = 0, ii=nblocks/2; i < nblocks/2; ++i, ++ii)
213  nfunc_per_block[ii] = coefs_a.coldim()->blocks()->size(i);
214  orbdim = new SCDimension(norbs * 2, nblocks, nfunc_per_block, id.c_str());
215  if (norbs) {
216  for (unsigned int i = 0; i < nblocks; ++i)
217  orbdim->blocks()->set_subdim(i, new SCDimension(nfunc_per_block[i]));
218  }
219  delete[] nfunc_per_block;
220  }
221  RefSCMatrix coefs = coefs_a.kit()->matrix(coefs_a.rowdim(),orbdim);
222  RefDiagSCMatrix evals = evals_a.kit()->diagmatrix(orbdim);
223  std::vector<unsigned int> orbsyms(norbs*2);
224  const unsigned int nao = coefs_a.rowdim().n();
225  for (unsigned int i = 0, ii=0; i < norbs; ++i, ++ii) { // alpha
226  for(unsigned int ao=0; ao<nao; ++ao) {
227  coefs(ao,ii) = coefs_a(ao,i);
228  }
229  evals(ii) = evals_a(i);
230  orbsyms[ii] = orbsyms_a[i];
231  }
232  for (unsigned int i = 0, ii=norbs; i < norbs; ++i, ++ii) { // alpha
233  for(unsigned int ao=0; ao<nao; ++ao) {
234  coefs(ao,ii) = coefs_b(ao,i);
235  }
236  evals(ii) = evals_b(i);
237  orbsyms[ii] = orbsyms_b[i];
238  }
239 
240  init(id, name, basis, integral, coefs, evals, orbsyms, order.nblocks(), blocked_orbs);
241 
242  }
243 
244 
245 } // end of namespace sc
246 
247 #endif // end of header guard
248 
249 // Local Variables:
250 // mode: c++
251 // c-file-style: "CLJ-CONDENSED"
252 // End:
sc::OrbitalSpace::evals
const RefDiagSCMatrix & evals() const
Returns the "eigenvalues" matrix.
sc::OrbitalSpace::coefs
const RefSCMatrix & coefs() const
Returns the coefficient matrix.
sc::OrbitalSpace::integral
const Ref< Integral > & integral() const
Returns the integral factory used to instantiate the coefficient matrix.
sc::OrbitalSpace::init
void init(const std::string &id, const std::string &name, const Ref< GaussianBasisSet > &basis, const Ref< Integral > &integral, const RefSCMatrix &coefs, const RefDiagSCMatrix &evals, const std::vector< unsigned int > &orbsyms, unsigned int nblocks, const std::vector< BlockedOrbital > &indexmap)
initialize the object by mapping the original space to a space with indexmap
sc::OrbitalSpace::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::BlockedOrbital
DecoratedOrbital< unsigned int > BlockedOrbital
Orbital in a blocked space.
Definition: orbitalspace.h:67
sc::StateOut
Definition: stateout.h:71
sc::OrbitalSpace::name
const std::string & name() const
Returns a self-contained expressive label.
sc::OrderedOrbitalSpace::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition: orbitalspace.timpl.h:55
sc::OrbitalSpace::nblocks
unsigned int nblocks() const
Returns the number of blocks.
sc::OrderedSpinOrbitalSpace::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition: orbitalspace.timpl.h:129
sc::OrderedOrbitalSpace
This is an OrbitalSpace ordered according to the Order type.
Definition: orbitalspace.h:701
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::OrderedSpinOrbitalSpace
Same as OrderedOrbitalSpace, except for spin-orbitals.
Definition: orbitalspace.h:725
sc::OrbitalSpace::basis
const Ref< GaussianBasisSet > & basis() const
Returns the AO basis set.

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.