~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/lib/libmoinfo/moinfo_slaterdeterminant.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include "moinfo.h"
 
3
 
 
4
extern FILE *infile, *outfile;
 
5
 
 
6
using namespace std;
 
7
 
 
8
namespace psi {
 
9
 
 
10
MOInfo::SlaterDeterminant::SlaterDeterminant()
 
11
{
 
12
}
 
13
 
 
14
 
 
15
MOInfo::SlaterDeterminant::~SlaterDeterminant()
 
16
{
 
17
}
 
18
 
 
19
 
 
20
/**
 
21
 * @fn MOInfo::SlaterDeterminant::is_closed_shell()
 
22
 */
 
23
bool MOInfo::SlaterDeterminant::is_closed_shell()
 
24
{
 
25
  for(int i=0;i<moinfo->get_nmo();i++)
 
26
    if(bits[i]!=bits[i+moinfo->get_nmo()])
 
27
      return(false);
 
28
  return(true);
 
29
}
 
30
 
 
31
 
 
32
/**
 
33
 * @fn MOInfo::SlaterDeterminant::is_spin_flip(SlaterDeterminant& det)
 
34
 */
 
35
bool MOInfo::SlaterDeterminant::is_spin_flipped(SlaterDeterminant& det)
 
36
{
 
37
  for(int i=0;i<moinfo->get_nmo();i++){
 
38
    if(bits[i]!=det.test(i+moinfo->get_nmo()))
 
39
      return(false);
 
40
    if(bits[i+moinfo->get_nmo()]!=det.test(i))
 
41
      return(false);
 
42
  }
 
43
  return(true);
 
44
}
 
45
 
 
46
 
 
47
/**
 
48
 * @fn MOInfo::SlaterDeterminant::print(int n)
 
49
 */
 
50
void MOInfo::SlaterDeterminant::print()
 
51
{
 
52
  fprintf(outfile,"|");
 
53
  for(int i=0;i<moinfo->get_nmo();i++){
 
54
    fprintf(outfile,"%s",get_occupation_symbol(i));
 
55
  }
 
56
  fprintf(outfile,">");
 
57
}
 
58
 
 
59
/**
 
60
 * @fn MOInfo::SlaterDeterminant::print(int n)
 
61
 */
 
62
void MOInfo::SlaterDeterminant::print_occ()
 
63
{
 
64
  fprintf(outfile,"|");
 
65
  int counter = 0;
 
66
  for(int h=0;h<moinfo->get_nirreps();h++){
 
67
    fprintf(outfile,"[");
 
68
    for(int i=0;i<moinfo->get_docc(h);i++){
 
69
      fprintf(outfile,"%c",get_occupation_symbol(counter));
 
70
      counter++;
 
71
    }
 
72
    for(int i=0;i<moinfo->get_actv(h);i++){
 
73
      fprintf(outfile,"%c",get_occupation_symbol(counter));
 
74
      counter++;
 
75
    }
 
76
    counter+=moinfo->get_avir(h);
 
77
    fprintf(outfile,"]");
 
78
  }
 
79
  fprintf(outfile,">");
 
80
}
 
81
 
 
82
/**
 
83
 * @fn MOInfo::SlaterDeterminant::get_internal_excitations(...)
 
84
 */
 
85
void MOInfo::SlaterDeterminant::get_internal_excitations(SlaterDeterminant& det,double& sign,
 
86
                                                 vector<pair<int,int> >& alpha_operators,
 
87
                                                 vector<pair<int,int> >& beta_operators)
 
88
{
 
89
  int ann, cre;
 
90
  int nmo = moinfo->get_nmo();
 
91
  bitdet bits_exc = det.get_bits();
 
92
  bitdet bits_tmp = bits;
 
93
  sign = 1.0;
 
94
  // Find one set of excitations at a time
 
95
  ann = -1; cre = -1;
 
96
  while(cre<nmo){
 
97
    while(++ann<nmo)
 
98
      if(bits[ann] && !bits_exc[ann]) break;
 
99
    while(++cre<nmo)
 
100
      if(!bits[cre] && bits_exc[cre]) break;
 
101
    if(cre<nmo){
 
102
      alpha_operators.push_back(make_pair(moinfo->get_all_to_occ(ann),moinfo->get_all_to_vir(cre)));
 
103
      sign *= annihilate(bits_tmp,ann);
 
104
      sign *=     create(bits_tmp,cre);
 
105
    }
 
106
  }
 
107
  ann = -1; cre = -1;
 
108
  while(cre<nmo){
 
109
    while(++ann<nmo)
 
110
      if(bits[ann+nmo] && !bits_exc[ann+nmo]) break;
 
111
    while(++cre<nmo)
 
112
      if(!bits[cre+nmo] && bits_exc[cre+nmo]) break;
 
113
    if(cre<nmo){
 
114
      beta_operators.push_back(make_pair(moinfo->get_all_to_occ(ann),moinfo->get_all_to_vir(cre)));
 
115
      sign *= annihilate(bits_tmp,ann+nmo);
 
116
      sign *=     create(bits_tmp,cre+nmo);
 
117
    }
 
118
  }
 
119
}
 
120
 
 
121
double MOInfo::SlaterDeterminant::annihilate(bitdet& bits_det,int so)
 
122
{
 
123
  if(bits_det.test(so)){
 
124
    bits_det.flip(so);
 
125
    double sign = 1.0;
 
126
    for(int i=0;i<so;i++)
 
127
      if(bits_det.test(i)) sign *= -1.0;
 
128
    return(sign);
 
129
  }
 
130
  else
 
131
    return(0.0);
 
132
}
 
133
 
 
134
double MOInfo::SlaterDeterminant::create(bitdet& bits_det,int so)
 
135
{
 
136
  if(!bits_det.test(so)){
 
137
    bits_det.flip(so);
 
138
    double sign = 1.0;
 
139
    for(int i=0;i<so;i++)
 
140
      if(bits_det.test(i)) sign *= -1.0;
 
141
    return(sign);
 
142
  }
 
143
  else
 
144
    return(0.0);
 
145
}
 
146
 
 
147
vector<int> MOInfo::SlaterDeterminant::get_aocc()
 
148
{
 
149
  vector<int> aocc;
 
150
  for(int i=0;i<moinfo->get_nmo();i++)
 
151
    if(bits[i])
 
152
      aocc.push_back(moinfo->get_all_to_occ(i));
 
153
  return(aocc);
 
154
}
 
155
 
 
156
vector<int> MOInfo::SlaterDeterminant::get_bocc()
 
157
{
 
158
  vector<int> bocc;
 
159
  for(int i=0;i<moinfo->get_nmo();i++)
 
160
    if(bits[i+moinfo->get_nmo()])
 
161
      bocc.push_back(moinfo->get_all_to_occ(i));
 
162
  return(bocc);
 
163
}
 
164
 
 
165
vector<int> MOInfo::SlaterDeterminant::get_avir()
 
166
{
 
167
  vector<int> avir;
 
168
  for(int i=0;i<moinfo->get_nmo();i++)
 
169
    if(!bits[i])
 
170
      avir.push_back(moinfo->get_all_to_vir(i));
 
171
  return(avir);
 
172
}
 
173
 
 
174
vector<int> MOInfo::SlaterDeterminant::get_bvir()
 
175
{
 
176
  vector<int> bvir;
 
177
  for(int i=0;i<moinfo->get_nmo();i++)
 
178
    if(!bits[i+moinfo->get_nmo()])
 
179
      bvir.push_back(moinfo->get_all_to_vir(i));
 
180
  return(bvir);
 
181
}
 
182
 
 
183
char MOInfo::SlaterDeterminant::get_occupation_symbol(int i)
 
184
{
 
185
  int occupation=bits[i]+bits[i+moinfo->get_nmo()];
 
186
  if(occupation==0)                     return('0');
 
187
  if(occupation==2)                     return('2');
 
188
  if((occupation==1) && bits.test(i))   return('+');
 
189
  if((occupation==1) && bits.test(i+moinfo->get_nmo())) return('-');
 
190
  return(' ');
 
191
}
 
192
 
 
193
}