diff options
Diffstat (limited to 'src/labat/atomlab.cc')
| -rw-r--r-- | src/labat/atomlab.cc | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/src/labat/atomlab.cc b/src/labat/atomlab.cc new file mode 100644 index 0000000..504a0d9 --- /dev/null +++ b/src/labat/atomlab.cc | |||
| @@ -0,0 +1,187 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <mt/config.h> | ||
| 21 | #include <fstream> | ||
| 22 | #include <iostream> | ||
| 23 | #include <unistd.h> | ||
| 24 | #include <fcntl.h> | ||
| 25 | #include <signal.h> | ||
| 26 | #include <sys/stat.h> | ||
| 27 | using namespace std; | ||
| 28 | |||
| 29 | const mstring LABAT=htchome()+sref("/bin/labat"); | ||
| 30 | |||
| 31 | const int SLOTS=8; | ||
| 32 | const int RUNLIMIT=600; | ||
| 33 | static int SLOT; | ||
| 34 | |||
| 35 | extern "C" { | ||
| 36 | static void FreeSlot(int dummy) | ||
| 37 | { | ||
| 38 | static int ok=0; | ||
| 39 | static char buf[256]; | ||
| 40 | if(!ok) { | ||
| 41 | ok=1; | ||
| 42 | sprintf(buf,"rm -rf /tmp/labat%d/",SLOT); | ||
| 43 | system(buf); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | static int AllocSlot() | ||
| 49 | { | ||
| 50 | struct stat FS; | ||
| 51 | char buf[256]; | ||
| 52 | for(SLOT=0;SLOT<SLOTS;SLOT++) { | ||
| 53 | sprintf(buf,"/tmp/labat%d/",SLOT); | ||
| 54 | if(stat(buf,&FS)!=0) { | ||
| 55 | signal(SIGTERM,FreeSlot); | ||
| 56 | signal(SIGINT,FreeSlot); | ||
| 57 | signal(SIGPIPE,FreeSlot); | ||
| 58 | sprintf(buf,"mkdir /tmp/labat%d/",SLOT); | ||
| 59 | system(buf); | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | return 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | /////////////////////////////////////////////////////////////////////////////// | ||
| 67 | |||
| 68 | struct CTLBasis { | ||
| 69 | int n,l,occ; | ||
| 70 | float e; | ||
| 71 | void SetEnergy(int Z) { | ||
| 72 | e=-0.5*float(Z*Z)/float(0.1+n*n*n+l*(l+1)*(l+2)); | ||
| 73 | } | ||
| 74 | }; | ||
| 75 | |||
| 76 | struct CTLData { | ||
| 77 | int atomz,its,basisn,exc; | ||
| 78 | float mix; | ||
| 79 | CTLBasis left[24],right[24]; | ||
| 80 | }; | ||
| 81 | |||
| 82 | static ostream& operator<<(ostream& out,const CTLData& ctl) | ||
| 83 | { | ||
| 84 | out<<ctl.atomz<<" "<<0<<"\n"; | ||
| 85 | out<<10<<" "<<40<<" "<<0.2<<"\n"; // Hermann-Skillman mesh | ||
| 86 | out<<ctl.mix<<" 0.00001 0.005\n"; // mix,error,? | ||
| 87 | out<<ctl.its<<" "<<0<<" "<<1<<" "<<0<<"\n"; // its ? step ? | ||
| 88 | out<<ctl.basisn<<" "<<2<<" "<<ctl.exc<<"\n"; // exc (C-A, B-H, GGA) | ||
| 89 | for(int i=0;i<ctl.basisn;i++) { | ||
| 90 | out<<ctl.left[i].n<<ctl.left[i].l<<0<<" "<<ctl.left[i].e | ||
| 91 | <<" "<<ctl.left[i].occ<<" "<<1<<" "<<0<<"\n"; | ||
| 92 | } | ||
| 93 | for(int i=0;i<ctl.basisn;i++) { | ||
| 94 | out<<ctl.right[i].n<<ctl.right[i].l<<0<<" "<<ctl.right[i].e | ||
| 95 | <<" "<<ctl.right[i].occ<<" "<<1<<" "<<0<<"\n"; | ||
| 96 | } | ||
| 97 | return out; | ||
| 98 | } | ||
| 99 | |||
| 100 | static void SetupLabat(mstring& resfile,int argc,char* argv[]) | ||
| 101 | { | ||
| 102 | CTLData ctl; | ||
| 103 | ctl.atomz=atoi(argv[1]); | ||
| 104 | ctl.its=atoi(argv[2]); | ||
| 105 | ctl.exc=atoi(argv[3]); | ||
| 106 | ctl.mix=atof(argv[4]); | ||
| 107 | resfile=argv[5]; | ||
| 108 | ctl.basisn=0; | ||
| 109 | int nl,nr,elecs=0; | ||
| 110 | for(int i=0;i<6;i++) { | ||
| 111 | for(int k=0;k<3;k++) { | ||
| 112 | nl=int(argv[6+i][2*k]-'0'); | ||
| 113 | nr=int(argv[6+i][2*k+1]-'0'); | ||
| 114 | if(nl>0||nr>0) { | ||
| 115 | ctl.left[ctl.basisn].n=i+1; | ||
| 116 | ctl.left[ctl.basisn].l=k; | ||
| 117 | ctl.left[ctl.basisn].occ=nl; | ||
| 118 | ctl.left[ctl.basisn].SetEnergy(ctl.atomz); | ||
| 119 | ctl.right[ctl.basisn].n=i+1; | ||
| 120 | ctl.right[ctl.basisn].l=k; | ||
| 121 | ctl.right[ctl.basisn].occ=nr; | ||
| 122 | ctl.right[ctl.basisn].SetEnergy(ctl.atomz); | ||
| 123 | ctl.basisn++; | ||
| 124 | } | ||
| 125 | elecs+=nl+nr; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | ctl.atomz+=elecs; | ||
| 129 | char buf[1024]; | ||
| 130 | sprintf(buf,"/tmp/labat%d/atomctrl.dat",SLOT); | ||
| 131 | ofstream os(buf); | ||
| 132 | os<<ctl; | ||
| 133 | cout<<"Atomnumber: "<<ctl.atomz<<" Electrons: "<<elecs<<"<BR>\n"; | ||
| 134 | cout<<"NOTE: if the program does >="<<ctl.its | ||
| 135 | <<" iterations, you must increase the number\n"; | ||
| 136 | cout<<"of iterations and re-run, to assure convergence.<BR>\n"; | ||
| 137 | cout<<"Also note that there is currently a maximum time limit of "<< | ||
| 138 | RUNLIMIT<<" seconds.<BR>\n"; | ||
| 139 | } | ||
| 140 | |||
| 141 | static void RunLabat() | ||
| 142 | { | ||
| 143 | char buf[1024]; | ||
| 144 | sprintf(buf,"cd /tmp/labat%d/\nulimit -t %d\n%s",SLOT,RUNLIMIT,LABAT.c_str()); | ||
| 145 | system(buf); | ||
| 146 | } | ||
| 147 | |||
| 148 | static void SaveLabat(const mstring& resfile) | ||
| 149 | { | ||
| 150 | const char* docroot=getenv("DOCROOT"); | ||
| 151 | if(docroot&&resfile.size()) { | ||
| 152 | char buf[1024]; | ||
| 153 | sprintf(buf,"cp -rfp /tmp/labat%d/atomdens.dat %s/%s", | ||
| 154 | SLOT,docroot,resfile.c_str()); | ||
| 155 | system(buf); | ||
| 156 | cout<<"<p>\n" | ||
| 157 | <<"Here you may download the density profile.\n" | ||
| 158 | <<"Example: Save the file as 'dens.dat', and load it from\n" | ||
| 159 | <<"matlab with 'load dens.dat'.\n" | ||
| 160 | <<"Then you can look at it with 'plot(dens(:,1),dens(:,2))'.\n" | ||
| 161 | <<"<p>\n"<<"<a href="<<resfile.c_str()<<">Get atomic density</a>\n"; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | main(int argc,char* argv[]) | ||
| 166 | { | ||
| 167 | if(argc<12) { | ||
| 168 | cerr<<"Usage: "<<argv[0]<<" <ion> <its> <exc> <mix> <resfile> <ssppdd>x6\n"; | ||
| 169 | exit(-1); | ||
| 170 | } | ||
| 171 | mstring resfile; | ||
| 172 | char buf[1024]; | ||
| 173 | if(AllocSlot()) { | ||
| 174 | cout<<"<h4>Running</h4>\n" | ||
| 175 | <<"<PRE>\n"; | ||
| 176 | cout.flush(); | ||
| 177 | SetupLabat(resfile,argc,argv); | ||
| 178 | RunLabat(); | ||
| 179 | cout<<"</PRE>\n" | ||
| 180 | <<"<h4>Done</h4>\n"; | ||
| 181 | SaveLabat(resfile); | ||
| 182 | FreeSlot(0); | ||
| 183 | } | ||
| 184 | else { | ||
| 185 | cout<<"No vacant slots at the moment. Try again later.\n"; | ||
| 186 | } | ||
| 187 | } | ||
