source: ThirdParty/mpqc_open/lib/perl/AtomicBasis.pm@ 860145

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 860145 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 5.7 KB
Line 
1#
2eval 'exec perl $0 $*'
3 if 0;
4
5package AtomicBasis;
6
7$fltrx = "((?:-?\\d+|-?\\d+\\.\\d*|-?\\d*\\.\\d+)(?:[eEdD][+-]?\\d+)?)";
8
9sub new {
10 my $this = shift;
11 my $class = ref($this) || $this;
12 my $self = {};
13 bless $self, $class;
14 $self->initialize(@_);
15 return $self;
16}
17
18sub initialize {
19 my $self = shift;
20
21 $self->{"pure_d"} = 1;
22 $self->{"pure_f_plus"} = 1;
23 $self->{"exponents"} = [];
24 $self->{"coefficients"} = [];
25 $self->{"am"} = [];
26 $self->{"pure"} = [];
27}
28
29sub default_pure {
30 my $self = shift;
31 my $am = shift;
32 if ($am == 2 && $self->{"pure_d"}) { return 1; }
33 elsif ($am > 2 && $self->{"pure_f_plus"}) { return 1; }
34 return 0;
35}
36
37my $amtypes = "SPDFGHIKLMN";
38
39sub am_string_to_number {
40 my $amstr = uc(shift);
41 if (length($amstr) != 1) {
42 die "invalid am string \"$amstr\"";
43 }
44 my $index = index($amtypes,$amstr);
45 if ($index == -1) {
46 die "am string \"$amstr\" not found";
47 }
48 return $index;
49}
50
51sub am_number_to_string {
52 my $am = shift;
53 return substr($amtypes,$am,1);
54}
55
56sub stdflt {
57 my $num = shift;
58 $num =~ s/D/e/;
59 $num =~ s/d/e/;
60 $num =~ s/E/e/;
61 return $num;
62}
63
64sub read_gaussian {
65 my $self = shift;
66 my $file = shift;
67 my $ishell = 0;
68 while (<$file>) {
69 if (/\*\*\*\*/) {
70 last;
71 }
72 elsif (/([A-Za-z]+) +([0-9]+) +([0-9.]+)/) {
73 my $amstr = uc($1);
74 my $nprim = $2;
75 my $scale = $3;
76 if ($scale != 1) {
77 die "cannot handle scale = $scale (must be 1)";
78 }
79 if ($amstr eq "SP") {
80 $self->{"am"}->[$ishell]->[0] = 0;
81 $self->{"am"}->[$ishell]->[1] = 1;
82 $self->{"pure"}->[$ishell]->[0] = 0;
83 $self->{"pure"}->[$ishell]->[1] = 0;
84 foreach my $i (0..$nprim-1) {
85 while (<$file>) { last; }
86 if (/$fltrx\s+$fltrx\s+$fltrx\s*$/) {
87 my $exp = $1;
88 my $coefs = $2;
89 my $coefp = $3;
90 $self->{"exponents"}->[$ishell]->[$i]
91 = stdflt($exp);
92 $self->{"coefficients"}->[$ishell]->[$i]->[0]
93 = stdflt($coefs);
94 $self->{"coefficients"}->[$ishell]->[$i]->[1]
95 = stdflt($coefp);
96 }
97 else {
98 die "bad exponent coefficient line";
99 }
100 }
101 }
102 else {
103 my $am = am_string_to_number($amstr);
104 $self->{"am"}->[$ishell]->[0] = $am;
105 $self->{"pure"}->[$ishell]->[0] = $self->default_pure($am);
106 foreach my $i (0..$nprim-1) {
107 while (<$file>) { last; }
108 if (/$fltrx\s+$fltrx\s*$/) {
109 my $exp = $1;
110 my $coef = $2;
111 $self->{"exponents"}->[$ishell]->[$i]
112 = stdflt($exp);
113 $self->{"coefficients"}->[$ishell]->[$i]->[0]
114 = stdflt($coef);
115 }
116 else {
117 die "bad exponent coefficient line";
118 }
119 }
120 }
121 $ishell++;
122 }
123 else {
124 die "could not parse line $_";
125 }
126 }
127}
128
129sub nshell {
130 my $self = shift;
131 my @exp = @{$self->{"exponents"}};
132 return $#exp + 1;
133}
134
135sub nprim {
136 my $self = shift;
137 my $ishell = shift;
138 my @exp = @{$self->{"exponents"}->[$ishell]};
139 return $#exp + 1;
140}
141
142sub ncon {
143 my $self = shift;
144 my $ishell = shift;
145 my @exp = @{$self->{"am"}->[$ishell]};
146 return $#exp + 1;
147}
148
149sub exp {
150 my $self = shift;
151 my $ishell = shift;
152 my $iprim = shift;
153 my $exp = $self->{"exponents"}->[$ishell]->[$iprim];
154 return $exp;
155}
156
157sub coef {
158 my $self = shift;
159 my $ishell = shift;
160 my $iprim = shift;
161 my $icon = shift;
162 my $coef = $self->{"coefficients"}->[$ishell]->[$iprim]->[$icon];
163 return $coef;
164}
165
166sub am {
167 my $self = shift;
168 my $ishell = shift;
169 my $icon = shift;
170 my $am = $self->{"am"}->[$ishell]->[$icon];
171 return $am;
172}
173
174sub pure {
175 my $self = shift;
176 my $ishell = shift;
177 my $icon = shift;
178 my $pure = $self->{"pure"}->[$ishell]->[$icon];
179 return $pure;
180}
181
182sub amstr {
183 my $self = shift;
184 my $ishell = shift;
185 my $icon = shift;
186 my $am = $self->{"am"}->[$ishell]->[$icon];
187 return am_number_to_string($am);
188}
189
190sub write_keyval {
191 my $self = shift;
192 my $file = shift;
193 foreach my $ishell (0..$self->nshell()-1) {
194 print $file " (type: [";
195 # write out am (and puream)
196 foreach my $icon (0..$self->ncon($ishell)-1) {
197 if ($icon > 0) { print $file " "; }
198 if ($self->pure($ishell,$icon)) {
199 printf $file "(am=%s puream=1)",
200 lc($self->amstr($ishell,$icon));
201 }
202 else {
203 printf $file "am=%s", lc($self->amstr($ishell,$icon));
204 }
205 }
206 print $file "]\n";
207 print $file " {exp";
208 # write out coef:0...
209 foreach my $icon (0..$self->ncon($ishell)-1) {
210 print $file " coef:$icon";
211 }
212 print "} = {\n";
213 foreach my $iprim (0..$self->nprim($ishell)-1) {
214 printf $file " %s", $self->exp($ishell,$iprim);
215 # write out coefficients
216 foreach my $icon (0..$self->ncon($ishell)-1) {
217 printf $file " %s", $self->coef($ishell,$iprim,$icon);
218 }
219 printf $file "\n";
220 }
221 print $file " })\n";
222 }
223}
224
2251;
Note: See TracBrowser for help on using the repository browser.