Debian Codegraph @

scatt.cpp

raw symbols SCIP
1 #include "scatt.h"
2 #include "deprecation.h"
3 Scatt::Scatt(Molecule *m){
4 mol=m;
5 f000=0.0;
6 Fmax=0.0;
7 resd=-1.0f;
8 }
9
10 QStringList Scatt::loadXRayScatteringFactors(){
11 QStringList xsfs;
12 QFile atomsf(":cmxray.txt");
13 atomsf.open(QIODevice::ReadOnly|QIODevice::Text);
14 QByteArray ba=atomsf.readAll();
15 QStringList all= QString(ba).split('\n');
16 atomsf.close();
17
18 for (int i=0; i<all.size(); i++){
19 if (all.at(i).startsWith('#'))continue;
20 QStringList tok=all.at(i).split(" ",skipEmptyParts);
21 if (tok.size()>9){
22 int an =tok.at(1).toInt()-1;
23 //W6+ 74 *DS 29.4936 1.42755 19.3763 0.104621 13.0544 5.93667 5.06412 11.1972 1.01074
24 xsfs.append(QString("%16 SFAC %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15!%17 %18\n")
25 .arg(mol->pse(tok.at(1).toInt()-1))
26 .arg(tok.at(3).toDouble())//a1
27 .arg(tok.at(4).toDouble())//b1
28 .arg(tok.at(5).toDouble())//a2
29 .arg(tok.at(6).toDouble())//b2
30 .arg(tok.at(7).toDouble())//a3
31 .arg(tok.at(8).toDouble())//b3
32 .arg(tok.at(9).toDouble())//a4
33 .arg(tok.at(10).toDouble())//b4
34 .arg(tok.at(11).toDouble())//c
35 .arg("fp")//f'
36 .arg("fdp")//f"
37 .arg("mu")//mu
38 .arg((an<94)?static_cast<double>(ff[an].rad):0.0)
39 .arg((an<94)?static_cast<double>(ff[an].mass):0.0)
40 .arg(tok.at(1).toInt())
41 .arg(tok.at(0))
42 .arg(tok.at(2))
43 );
44 }
45 }
46 return xsfs;
47 }
48
49 QStringList Scatt::loadElectronScatteringFactors(){
50 QStringList esfs;
51 QFile atomsf(":peng_eas");
52 atomsf.open(QIODevice::ReadOnly|QIODevice::Text);
53 QByteArray ba=atomsf.readAll();
54 QStringList all= QString(ba).split('\n');
55 atomsf.close();
56 //#Element Z a1 a2 a3 a4 b1 b2 b3 b4 s
57 // 0 1 2 3 4 5 6 7 8 9 10
58 for (int i=0; i<all.size(); i++){
59 if (all.at(i).startsWith('#'))continue;
60 QStringList tok=all.at(i).split(" ",skipEmptyParts);
61 if (tok.size()>9){
62 int an =tok.at(1).toInt()-1;
63 esfs.append(QString("SFAC %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15\n")
64 .arg(tok.at(0))
65 .arg(tok.at(2).toDouble())//a1
66 .arg(tok.at(6).toDouble())//b1
67 .arg(tok.at(3).toDouble())//a2
68 .arg(tok.at(7).toDouble())//b2
69 .arg(tok.at(4).toDouble())//a3
70 .arg(tok.at(8).toDouble())//b3
71 .arg(tok.at(5).toDouble())//a4
72 .arg(tok.at(9).toDouble())//b4
73 .arg(0.0)
74 .arg(0.0)
75 .arg(0.0)
76 .arg(0.0)
77 .arg((an<94)?static_cast<double>(ff[an].rad):0.0)
78 .arg((an<94)?static_cast<double>(ff[an].mass):0.0)
79 );
80 }
81 }
82 all.clear();
83 QFile ionsf(":ions_eas");
84 ionsf.open(QIODevice::ReadOnly|QIODevice::Text);
85 ba=ionsf.readAll();
86 all= QString(ba).split('\n');
87 ionsf.close();
88 for (int i=0; i<all.size(); i++){
89 if (all.at(i).startsWith('#'))continue;
90 QStringList tok=all.at(i).split(" ", skipEmptyParts);
91 if (tok.size()>10){
92 int an = tok.at(1).toInt();
93 esfs.append(QString("SFAC %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15\n")
94 .arg(tok.at(0))
95 .arg(tok.at(2).toDouble())//a1
96 .arg(tok.at(6).toDouble())//b1
97 .arg(tok.at(3).toDouble())//a2
98 .arg(tok.at(7).toDouble())//b2
99 .arg(tok.at(4).toDouble())//a3
100 .arg(tok.at(8).toDouble())//b3
101 .arg(tok.at(5).toDouble())//a4
102 .arg(tok.at(9).toDouble())//b4
103 .arg(tok.at(10).toDouble())//c
104 .arg(0.0)
105 .arg(0.0)
106 .arg(0.0)
107 .arg((an<94)?static_cast<double>(ff[an].rad):0.0)
108 .arg((an<94)?static_cast<double>(ff[an].mass):0.0)
109 );
110 }
111 //else printf("??%d %s\n",tok.size(),all.at(i).toStdString().c_str());
112 }
113 return esfs;
114 }
115
116 void Scatt::setSCAT(QStringList tok){
117 if (tok.size()<16)return;
118 int an = mol->getOZ(tok.at(1));
119 if (an<0)return;
120 for (int i=0; i<9; i++) {
121 ff[an].ab4c[i]=tok.at(2+i).toFloat();
122 // qDebug()<<i+2<<ff[an].ab4c[i];
123 }
124 ff[an].fpcu=ff[an].fpmo=ff[an].fpag = tok.at(11).toFloat();
125 ff[an].fppcu=ff[an].fppmo=ff[an].fppag = tok.at(12).toFloat();
126 ff[an].mucu=ff[an].mumo=ff[an].muag = tok.at(13).toFloat();
127 ff[an].rad=tok.at(14).toFloat();
128 ff[an].mass=tok.at(15).toFloat();
129 }
130
131 void Scatt::setDISP(QStringList tok){
132 if (tok.size()<4)return;
133 int an = mol->getOZ(tok.at(1));
134 ff[an].fpcu=ff[an].fpmo=ff[an].fpag = tok.at(2).toFloat();
135 if (tok.size()<4)return;
136 ff[an].fppcu=ff[an].fppmo=ff[an].fppag = tok.at(3).toFloat();
137 if (tok.size()<5)return;
138 ff[an].mucu=ff[an].mumo=ff[an].muag = tok.at(4).toFloat();
139
140 }
141
142 float Scatt::fprime(int an,int radiation){
143 switch (radiation){
144 case SCATTCU: return ff[an].fpcu;
145 case SCATTMO: return ff[an].fpmo;
146 case SCATTAG: return ff[an].fpag;
147 default: return ff[an].fpcu;
148 }
149 }
150
151 float Scatt::fdprime(int an,int radiation){
152 switch (radiation){
153 case SCATTCU: return ff[an].fppcu;
154 case SCATTMO: return ff[an].fppmo;
155 case SCATTAG: return ff[an].fppag;
156 default: return ff[an].fppcu;
157 }
158 }
159
160 float Scatt::atomformfactor(int an, float s){
161 float erg=0.0;
162 for (int i=0; i<4;i++){
163 erg+=ff[an].ab4c[2*i]*exp(-ff[an].ab4c[2*i+1]*s);
164 }
165 erg+=ff[an].ab4c[8];
166 return erg;
167 }
168
169 float Scatt::FF(V3 hkl,int radiation,float &phang,float &I){
170 const float twopi=M_PIf*2.0f;
171 const float twopi2=M_PIf*M_PIf*2.0f;
172 phang=0;
173 float A=0.f,Aa=0.f;
174 float B=0.f,Ba=0.f;
175 float s2=sintl2(hkl)*0.25f;
176 //printf("s2 %f %f\n",s2,resd);
177 if ((s2< mol->hklShellLow)||(s2> mol->hklShellHig)){
178 phang=0.0f;
179
180 I=-666.0f;
181 return 0.0f;
182 }
183 if (s2>0.001)resd=fmax(s2,resd);
184 QList<float> f0;
185 f000=0.0;
186 for (int i=0; i<isfac.size(); i++) f0.append(atomformfactor(isfac.at(i),s2));
187 for (int i=0; i<xyz.size(); i++){
188 float sof = sofs.at(i);
189 int an= isfac.at(type.at(i));
190 f000+=sof*(an+1);
191 float p=(float)(twopi*(xyz.at(i)*hkl));
192 float fp=fprime(an,radiation);
193 float fpp=fdprime(an,radiation);
194 //T = 8*(pi**2)*Uiso*sin(theta/lambda)**2
195 if (isos.at(i)) sof*=expf(bet.at(i).m11*s2);
196 else {
197 sof*=expf(-twopi2* ((hkl*bet.at(i))*hkl));
198 }// */
199 float cs=cosf(p),si=sinf(p);
200 //float cs=1,si=0.0;
201 float a=(f0.at(type.at(i))+fp);
202 A+= sof*(a*cs-fpp*si);
203 B+= sof*(a*si+fpp*cs);
204 Aa+=sof*(a*cs);
205 Ba+=sof*(a*si);
206 }
207 I=A*A+B*B;
208 float Ia=Aa*Aa+Ba*Ba;
209 phang=atan2f(Ba,Aa)*180.0f/M_PIf;
210 phang=fmod(720.01f+phang,360)-0.01f;
211 float fc=sqrtf(Ia);
212 if (s2>0.001) Fmax=fmax(Fmax,fc);
213 return fc;
214 }
215 float Scatt::F(int h, int k, int l,int radiation,float &phang,float &disp){
216 const float twopi=M_PIf*2.0f;
217 const float twopi2=M_PIf*M_PIf*2.0f;
218 phang=0;
219 float A=0,Aa=0;
220 f000=0.0;
221 float B=0,Ba=0;
222 Matrix N=Matrix(mol->cell.as,0,0,0,mol->cell.bs,0,0,0,mol->cell.cs),beta_,beta;//,ucc;
223 float s2=sintl2(h,k,l)*0.25f;
224 //printf("Fs2 %f %f\n",s2,resd);
225 if (s2>0.001)resd=fmin(0.5/sqrt(s2),resd);
226 int ns = mol->cell.symmops.size();
227 int na = mol->asymm.size();
228 for (int s=0; s<ns; s++){
229 for (int i=0; i<na; i++){
230 int an = mol->asymm.at(i).an;
231 if (an<0) continue;
232 bool iso=(mol->asymm.at(i).isIso);
233 if (!iso){
234 beta=(N*mol->asymm.at(i).uf*N);
235 mol->Usym(beta,mol->cell.symmops.at(s),beta_);
236 }
237 float sof = mol->asymm.at(i).sof;
238 f000+=sof*(an+1);
239 V3 uvw = mol->cell.symmops.at(s)*mol->asymm[i].frac+mol->cell.trans.at(s);
240
241 V3 hkl(h,k,l);
242 float p=twopi*uvw*hkl;
243 float f0=atomformfactor(an,s2);
244 float fp=fprime(an,radiation);
245 float fpp=fdprime(an,radiation);
246 //T = 8*(pi**2)*Uiso*sin(theta/lambda)**2
247 if (iso) sof*=exp(-4*twopi2*mol->asymm.at(i).uf.m11*s2);
248 else {
249 sof*=exp(-twopi2* ((hkl*beta_)*hkl));
250
251 }
252 float cs=cos(p),si=sin(p);
253 A+=sof*((f0+fp)*cs-fpp*si);
254 B+=sof*((f0+fp)*si+fpp*cs);
255 Aa+=sof*((f0+fp)*cs);
256 Ba+=sof*((f0+fp)*si);
257 }
258 }
259 float I=A*A+B*B;
260 float Ia=Aa*Aa+Ba*Ba;
261 phang=atan2(Ba,Aa)*180.0/M_PI;
262 phang=fmod(720.01+phang,360)-0.01;
263 disp=I;
264 float fc=sqrt(Ia);
265 if (s2>0.001) Fmax=fmax(Fmax,fc);
266 return fc;
267 }
268
269 QString Scatt::myfcf(QString fn){
270 // qDebug()<<mol->hklf;
271 // qDebug()<<mol->hklScale<<mol->hklSigmaScale;
272 if ((mol->hklf<3)||(mol->hklf>4)) return "";
273 // const float twopi=M_PI*2.0;
274 const float twopi2=M_PIf*M_PIf*2.0f;
275
276 Rec *lr=NULL,ob;
277 QString base=fn, mfcf=fn, hklf=fn;
278 hklf=hklf.replace(QRegularExpression("(.res$)|(.ins$)"),".hkl");
279 mfcf=mfcf.replace(QRegularExpression("(.res$)|(.ins$)"),".fcf6");
280 base=base.replace(QRegularExpression("(.res$)|(.ins$)"),"");
281 base=base.section('/', -1);
282 FILE *hkl=fopen(hklf.toStdString().c_str(),"rt");
283 if (hkl==NULL) {fprintf(stderr,"can't open hkl\n"); return "";}
284 int nr=0;
285 char line[128];
286 int wl=0;
287 if (fabs(mol->cell.wave-0.71073)<0.01) wl=SCATTMO;
288 else if (fabs(mol->cell.wave-1.5418)<0.01) wl=SCATTCU;
289 else if (fabs(mol->cell.wave-0.56083)<0.01) wl=SCATTAG;
290 else wl=-1;
291 int nnr=0;
292 mol->hklShellLow = pow(0.5/mol->hklShellLow,2);
293 mol->hklShellHig = pow(0.5/mol->hklShellHig,2);
294 // qDebug()<<"@@"<<mol->hklShellLow<<mol->hklShellHig;
295 while (!feof(hkl)){
296 if (fgets(line,120,hkl)) {;}
297 nnr++;
298 }
299 rewind(hkl);
300 lr=(Rec*) malloc(sizeof(Rec)*nnr);
301 FILE *fc6=fopen(mfcf.toStdString().c_str(),"wt");
302 if (fc6==NULL) {
303 fprintf(stderr,"can't open %s\n",mfcf.toStdString().c_str());
304 qDebug()<<"can't open " << mfcf;
305 return "";
306 }
307
308 //FILE *tst=NULL;//:qfopen("scale_test_123.456","wt");
309 if (1) {
310 Matrix N=Matrix(mol->cell.as,0,0,0,mol->cell.bs,0,0,0,mol->cell.cs),beta_,beta;//,ucc;
311 type.clear();
312 bet.clear();
313 sofs.clear();
314 xyz.clear();
315 isos.clear();
316 int ns = mol->cell.symmops.size();
317 int na = mol->asymm.size();
318 for (int s=0; s<ns; s++){
319 for (int i=0; i<na; i++){
320 int an = mol->asymm.at(i).an;
321 if (an<0) continue;
322 if (!isfac.contains(an)) isfac.append(an);
323 type.append(isfac.indexOf(an));
324 bool iso=(mol->asymm.at(i).isIso);
325 if (!iso){
326 beta=(N*mol->asymm.at(i).uf*N);
327 mol->Usym(beta,mol->cell.symmops.at(s),beta_);
328 }else{beta_.m11=-4*twopi2*mol->asymm.at(i).uf.m11;}
329 isos.append(iso);
330 bet.append(beta_);
331 float sof = mol->asymm.at(i).sof;
332 sofs.append(sof);
333 xyz.append(mol->cell.symmops.at(s)*mol->asymm[i].frac+mol->cell.trans.at(s));
334 }
335 }
336 }
337
338
339
340
341 // printf("wave:%f %f %f %f %d %d wl=%d\n",mol->cell.wave,fabs(mol->cell.wave-0.71073),fabs(mol->cell.wave-1.5418),fabs(mol->cell.wave-0.56083), mol->cell.ns0, mol->cell.symmops.size(),wl);
342
343 /*printf("hklf N=%d s:%g \n%g %g %g\n%g %g %g\n%g %g %g\nsm: %g \n",mol->hklf,mol->hklScale ,
344 mol->hklMat.m11,mol->hklMat.m12,mol->hklMat.m13,
345 mol->hklMat.m21,mol->hklMat.m22,mol->hklMat.m23,
346 mol->hklMat.m31,mol->hklMat.m32,mol->hklMat.m33,
347 mol->hklSigmaScale);*/
348 while (!feof(hkl)){
349 if (fgets(line,120,hkl)) {;}
350 if (feof(hkl))continue;
351 if (strlen(line)<28) continue;
352 char chkl[13],cisig[17];
353 for (int ci=0; ci<12; ci++) chkl[ci]=line[ci];
354 chkl[12]='\0';
355 for (int ci=0; ci<16; ci++) cisig[ci]=line[ci+12];
356 cisig[16]='\0';
357 sscanf(chkl,"%4d%4d%4d", &ob.ih, &ob.ik, &ob.il);
358 sscanf(cisig,"%8f%8f", &ob.fo, &ob.si);
359 if ((ob.ih==0)&&(ob.il==0)&&(ob.ik==0)) {
360 // printf("#[%d,%d,%d,%d]%s",nr,ob.ih,ob.ik,ob.il,line);
361
362 break;
363 }
364 V3 hkl=V3(ob.ih,ob.ik,ob.il)*mol->hklMat;
365 ob.ih=hkl.x;
366 ob.ik=hkl.y;
367 ob.il=hkl.z;
368 ob.fo*=mol->hklScale;
369 ob.si=(mol->hklScale*mol->hklSigmaScale*ob.si);
370 if (mol->hklf==3){
371 double xxx=fmax(0.01,ob.si);
372 ob.si=2.0*xxx * fabs(fmax(fabs(ob.fo),xxx));
373 ob.fo*=ob.fo;
374 }
375 //ob.fc=FF(hkl,wl,ob.phi,ob.dis);
376 // if ((ob.ih==1)&&(ob.ik==0)&&(ob.il==0)){ printf("%4d%4d%4d %18.9f %18.9f\n",ob.ih,ob.ik,ob.il,ob.fo,ob.si); }
377 // ob.fc=F(ob.ih,ob.ik,ob.il,wl,ob.phi,ob.dis);
378
379 lr[nr]=ob;
380 nr++;
381 }
382 // qDebug()<<resd <<0.5/sqrt(resd);
383 //resd=0.5f/sqrtf(resd);
384 //printf("resd %f\n",resd);
385 // for (int iw=0; iw<xyz.size(); iw++){ qDebug()<<type.at(iw)<<sofs.at(iw)<<xyz.at(iw).x<<xyz.at(iw).y<<xyz.at(iw).z; }
386 //if (tst!=NULL) fclose(tst);
387
388 float myosf=0.0;
389 for (int i=0; i<nr; i++){
390 V3 uvw=V3(lr[i].ih,lr[i].ik,lr[i].il);
391 V3 m=uvw;
392 float p,q=lr[i].phi;
393 lr[i].phi=fmod(720.0+q,360.0);
394 for (int s=0; s<mol->cell.ns0;s++){
395 float t=1.0;
396 V3 nhkl=uvw*mol->cell.symmops.at(s);
397 // if((nl<0)||((nl==0)&&(nk<0))||((nl==0)&&(nk==0)&&(nh<0)))
398 //if((nl<0)||((nl==0)&&(nk<0))||((nl==0)&&(nk==0)&&(nh<0)))
399 if((nhkl.z<0)||((nhkl.z==0)&&(nhkl.y<0))||((nhkl.z==0)&&(nhkl.y==0)&&(nhkl.x<0))) {
400 nhkl.x*=-1;
401 nhkl.y*=-1;
402 nhkl.z*=-1;
403 t=-1.0;
404 }
405 if ((nhkl.z<m.z)||((nhkl.z==m.z)&&(nhkl.y<m.y))||((nhkl.z==m.z)&&(nhkl.y==m.y)&&(nhkl.x<=m.x))) continue;
406 m=nhkl;
407 //p=u*sy[9][k]+v*sy[10][k]+w*sy[11][k];
408 p=uvw*mol->cell.trans.at(s);
409 lr[i].phi=fmod(719.99+t*fmod(q-360.0*p,360.0),360.0)+0.01;
410 /* if (m==V3(1,1,0)) {printf("?%4d%4d%4d sym=%d %g \n %4g%4g%4g fo%12.6f si%12.6f fc%12.6f phi%12.3f %d %f %f (%g %g %g)\n",lr[i].ih,lr[i].ik,lr[i].il,s,t,
411 nhkl.x,nhkl.y,nhkl.z,
412 lr[i].fo,lr[i].si,lr[i].fc,lr[i].phi,i,q,p, mol->cell.trans.at(s).x,mol->cell.trans.at(s).y,mol->cell.trans.at(s).z);}*/
413 }
414 lr[i].ih=m.x;
415 lr[i].ik=m.y;
416 lr[i].il=m.z;
417 }
418 sorthkl(nr,lr);
419 int n=-1;
420 // float sw=0.,swxy=0.0,swx=0.0,swy=0.0,swx2=0.0,sfo=0,sfoc=0;
421 float swxy=0.0,swx2=0.0,sfo=0,sfoc=0;;
422 {int i=0;
423 while(i<nr){
424 float t=0.;
425 float u=0.;
426 float v=0.;
427 float v2=0.;
428 float ws=0;
429 int m;
430 int k=i;
431 while ((i<nr)&&(lr[i].ih==lr[k].ih)&&(lr[i].ik==lr[k].ik)&&(lr[i].il==lr[k].il)) {
432 t=t+1.;
433 float w=fmax(4.0,lr[i].fo/lr[i].si)/lr[i].si;//1.0;//
434 ws+=w;
435 u+=lr[i].fo*w;//*lr[i].fc*lr[i].fc/lr[i].dis;
436 v+=1./(lr[i].si*lr[i].si);
437 v2+=lr[i].si;
438 // p=lr[i].phi;
439 // ddi+=lr[i].dis;
440 // if (t>1) {printf("!%4d%4d%4d fo%12.6f sig%12.6f fc%12.6f phi%12.3f i%d k%dw=%f dis%f\n",lr[i].ih,lr[i].ik,lr[i].il,lr[i].fo,lr[i].si,lr[i].fc,lr[i].phi,i,k,w,lr[i].dis);}
441 i++;
442 }
443 m=n+1;
444 float yy=(u/ws);
445 lr[m].fo = sqrt(fmax(0.0f,yy));
446 lr[m].so=sqrt(lr[m].fo*lr[m].fo+sqrt(1./v))-lr[m].fo;
447 lr[m].si=1.0/sqrt(v);
448 n=m;
449 lr[n].ih=lr[k].ih;
450 lr[n].ik=lr[k].ik;
451 lr[n].il=lr[k].il;
452 }
453 //printf("%d %d %d \n",nr,n,i);
454 }
455 n++;
456 nr=n;
457 for (int i=0; i<nr; i++){
458 V3 chkl=V3(lr[i].ih,lr[i].ik,lr[i].il);
459 lr[i].fc=0.0;
460 lr[i].fc=FF(chkl,wl,lr[i].phi,lr[i].dis);
461 lr[i].fo =lr[i].fo * (lr[i].fc*lr[i].fc/lr[i].dis);//correct for dispersion
462 if (lr[i].dis<=-665.0f) {
463 lr[i].fc=0.0;
464 continue;
465 }
466 if ((mol->exti!=-666.0)&&(mol->swat==-666.0)){
467 lr[i].fc*=pow(1 + 0.001 * mol->exti * lr[i].fc * lr[i].fc *mol->cell.wave * mol->cell.wave /sqrt(sintl2(chkl)),-0.25);
468 }
469 float xx=lr[i].fc*lr[i].fc;
470 float yy=lr[i].fo*lr[i].fo;
471 float v=1.0/(lr[i].si*lr[i].si);
472 if (xx>0.001){
473 swx2+=v*xx*xx;
474 swxy+=v*yy*xx;
475 }
476 }
477 float osf2=(mol->osf<=0.0)?swxy/swx2:mol->osf*mol->osf;//myosf;
478 myosf=sqrt(osf2);
479 // qDebug() << mol->osf << myosf << osf2 << swxy/swx2<<swxy <<swx2;
480 //printf("%g %g %g\n",myosf,osf2,swxy/swx2);
481 type.clear();
482 bet.clear();
483 sofs.clear();
484 xyz.clear();
485 isos.clear();
486 // myosf=mol->osf;
487 resd=0.5f/sqrtf(resd);
488 //printf("???? %f \n",resd);
489 fprintf(fc6,
490 "#\n# h,k,l, Fo-squared, sigma(Fo-squared), Fc and phi(calc)\n#\ndata_%s\n_shelx_title '%s'\n_shelx_refln_list_code 6\n"
491 "_shelx_F_calc_maximum %6.2f\n_exptl_crystal_F_000 %6.2f\n_reflns_d_resolution_high %6.4f\n\nloop_\n_space_group_symop_operation_xyz\n"
492 ,base.toStdString().c_str()
493 ,mol->titl.toStdString().c_str()
494 ,Fmax
495 ,f000
496 ,resd
497 );
498 for (int s=0; s<mol->cell.symmops.size();s++)
499 fprintf(fc6,"'%s'\n",mol->symmcode2human(s).trimmed().toStdString().c_str());
500 fprintf(fc6,
501 "\n_cell_length_a %8.4f\n_cell_length_b %8.4f\n_cell_length_c %8.4f\n_cell_angle_alpha %7.3f\n_cell_angle_beta %7.3f\n_cell_angle_gamma %7.3f\n\n"
502 "loop_\n_refln_index_h\n_refln_index_k\n_refln_index_l\n_refln_F_squared_meas\n_refln_F_squared_sigma\n_refln_F_calc\n_refln_phase_calc\n",
503 mol->cell.a,mol->cell.b,mol->cell.c,mol->cell.al,mol->cell.be,mol->cell.ga
504 );
505 int igut=0;
506 for (int i=0; i<nr; i++){
507 /*
508 fprintf(fc6,"%d %d %d %.2f %.2f %2f %.2f %.1f %f\n"
509 ,lr[i].ih
510 ,lr[i].ik
511 ,lr[i].il
512 // ,(pow(lr[i].fo/mol->osf,2.0))/(1.0+lr[i].dis)
513 ,pow(lr[i].fo/mol->osf,2.0)
514 ,lr[i].si/(mol->osf*mol->osf)
515 ,sqrt(lr[i].dis)
516 ,lr[i].fc
517 ,lr[i].phi
518 ,lr[i].fc*lr[i].fc
519 // ,lr[i].dis
520 );// */
521
522 float iosig = powf(lr[i].fo/myosf,2.0f)/(lr[i].si/(osf2));
523 if ((lr[i].fc>0.001)&& (iosig>-1.0)){
524 igut++;
525 sfo+=lr[i].fo/myosf;
526 sfoc+=fabs(lr[i].fo/myosf-lr[i].fc);
527 }
528 if (lr[i].fc>0.001f)
529 fprintf(fc6,"%d %d %d %.2f %.2f %.2f %.1f\n"
530 ,lr[i].ih
531 ,lr[i].ik
532 ,lr[i].il
533 // ,(pow(lr[i].fo/mol->osf,2.0))/(1.0+lr[i].dis)
534 ,powf(lr[i].fo/myosf,2.0f)
535 ,lr[i].si/(osf2)
536 //,sqrt(lr[i].dis)
537 ,lr[i].fc
538 ,lr[i].phi
539 // ,lr[i].fc*lr[i].fc
540 // ,lr[i].dis
541 );// */
542 }
543 fclose(hkl);
544 fclose(fc6);
545 //printf("R1=%f %d %d %g %g \n",sfoc/sfo,igut,nr,sfoc,sfo);
546 return mfcf;
547 }
548
549 float Scatt::sintl2(int h,int k, int l){
550 V3 H=V3(h,k,l);
551 float s=H*mol->cell.Gi*H;
552 return s;
553 }
554 float Scatt::sintl2(V3 H){
555 float s=H*mol->cell.Gi*H;
556 return s;
557 }
558 void Scatt::sorthkl(int nr, Rec r[]){
559 /*! sorts the reflection list
560 */
561 Rec *hilf= (Rec*) malloc(sizeof(Rec)*nr);
562 if (hilf==NULL)return ;
563 int i,j,k,nj,ni,spalte;int index[4096];
564 for (spalte=0; spalte<3; spalte++){
565 j=-999999;
566 k=999999;
567 switch (spalte) {
568 case 0: for (i=0; i<nr; i++){ j=(j<r[i].ih)?r[i].ih:j; k=(k>r[i].ih)?r[i].ih:k; } break;
569 case 1: for (i=0; i<nr; i++){ j=(j<r[i].ik)?r[i].ik:j; k=(k>r[i].ik)?r[i].ik:k; } break;
570 case 2: for (i=0; i<nr; i++){ j=(j<r[i].il)?r[i].il:j; k=(k>r[i].il)?r[i].il:k; } break;
571 }
572 nj=-k;
573 ni=(nj+j+1);
574 for (i=0; i<=ni; i++) index[i]=0;
575 for (i=0; i<nr; i++){
576 switch (spalte){
577 case 0: j=r[i].ih+nj; break;
578 case 1: j=r[i].ik+nj; break;
579 case 2: j=r[i].il+nj; break;
580 }
581 index[j]++;/*brauch ich das? -->JA!*/
582 hilf[i].ih=r[i].ih;
583 hilf[i].ik=r[i].ik;
584 hilf[i].il=r[i].il;
585 hilf[i].fo=r[i].fo;
586 hilf[i].so=r[i].so;
587 hilf[i].si=r[i].si;
588 hilf[i].fc=r[i].fc;
589 hilf[i].dis=r[i].dis;
590 hilf[i].phi=r[i].phi;
591 }/*/4*/
592 j=0;
593 for (i=0; i<ni; i++){
594 k=j;
595 j+=index[i];
596 index[i]=k;
597 }/*/5*/
598 for (i=0; i<nr;i++){
599 switch (spalte) {
600 case 0: j=hilf[i].ih +nj;break;
601 case 1: j=hilf[i].ik +nj;break;
602 case 2: j=hilf[i].il +nj;break;
603 }
604 index[j]++;
605 j=index[j]-1;
606 r[j].ih=hilf[i].ih;
607 r[j].ik=hilf[i].ik;
608 r[j].il=hilf[i].il;
609 r[j].fo=hilf[i].fo;
610 r[j].so=hilf[i].so;
611 r[j].si=hilf[i].si;
612 r[j].fc=hilf[i].fc;
613 r[j].dis=hilf[i].dis;
614 r[j].phi=hilf[i].phi;
615 }/*/6*/
616 }/*/spalten*/
617 free(hilf);
618 }
619