/
pgeom.c
1332 lines (1094 loc) · 37.1 KB
/
pgeom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
$Id: pgeom.c,v 1.37 2008/02/18 01:18:48 oliver Exp $
Ouline of the program:
======================
Calculate positions in atomistic model of a transmembrane pore.
INPUT:
[all lengths in Angstroem = 10^(-10)m,
all distances are 'bounding-box' (include all pseudoatoms)]
Router outer model radius
For each domain of the model (cylindrical symmetry):
Rpore inner pore radius
L total length of domain
spec species (determines rA)
rho(z) shapefunction, describing shape of inner wall
OUTPUT:
list of atomic coordinates in pdb format
GROMACS topology file (itp)
*/
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "xgtypes.h"
#include "xg.h"
#include "util.h"
#include "mol_data.h"
#include "cylint.h"
#include "nr.h"
/*
functions
pore shape functions
given: z(rho), z
need: z^{-1}(rho) === rho(z)
*/
#ifdef DEBUG
#ifndef TESTCASE
#define TESTCASE
#endif
#endif
/* internal test for integration routine cylint() */
#ifdef TESTCASE
real cylconst (real r, real phi, real z) {
return r;
}
real cylcos (real r, real phi, real z) {
return r*cos(phi);
}
real cyl3 (real r, real phi, real z) {
return exp(-r)*cos(phi)*cos(phi)*z*z;
}
#define K1 2.333 /* kT nm^-2 */
real harmonic (real r, real phi, real z) {
return K1/2.0 * r*r;
}
#endif /* TESTCASE */
double constant (double z, double z1, double z2, double r1, double r2)
{
assert(r1 == r2);
return r1;
};
double linear (double z, double z1, double z2, double r1, double r2)
{
double m, t;
assert (z1 != z2);
assert (r1 != r2);
m = (z2 - z1)/(r2 - r1);
t = z1 - m*r1;
return (z - t)/m;
};
struct domain ini_domain (enum domaintypes t, char * desc, double len,
double (*shapefunction)(), struct spec *sp,
double r1, double r2,
struct domain *prev, struct domain *next)
/* these parameters have to be given by the user. All other
parameters are calculated by the programme (eventually...)
*/
{
double rA;
struct domain this;
rA = sp->radius;
this.type = t;
this.description = desc;
this.l = len;
this.rho = shapefunction;
this.species = sp;
this.r1 = r1;
this.r2 = r2;
this.rho1 = r1 + rA;
this.rho2 = r2 + rA;
this.prev = prev;
this.next = next;
/* r_outer is initialized with g->r_outer later on. It is not really
supossed to be variable on a per domain basis, but conceptually
it belongs here */
this.r_outer = 0;
this.rho_outer = 0;
/* initialize unknowns with zero values */
this.z1 = 0.0;
this.z2 = 0.0;
this.q = 0;
this.dz = 0.0;
this.first_site = 0;
this.last_site = 0;
return this;
}
int standard_geom (struct std_input *in, struct domain domain_list[MAXDOMAINS])
{
/* setup standard geometry: 3 domains M-P-M, length, radii */
#define NDOMAINS_STD 3
assert(NDOMAINS_STD <= MAXDOMAINS + 1);
domain_list[0] = ini_domain(MOUTH, "intracellular mouth region", in->l_mouth,
&linear, &species[in->specid],
in->r_mouth, in->r_pore,
NULL, &domain_list[1]);
domain_list[1] = ini_domain(PORE, "transmembrane pore region", in->l_pore,
&constant, &species[in->specid],
in->r_pore, in->r_pore,
&domain_list[0], &domain_list[2]);
domain_list[2] = ini_domain(MOUTH, "extracellular mouth region", in->l_mouth,
&linear, &species[in->specid],
in->r_pore, in->r_mouth,
&domain_list[1], NULL);
return NDOMAINS_STD;
};
int datafile_geom (struct std_input *in, struct domain domain_list[MAXDOMAINS])
{
/* read geometry from file:
# comment (skipped)
RADIUS r_outer
MOUTH r_upper r_lower length [species]
PORE r_upper r_lower length [species]
...
*/
FILE *geometry;
char line[STRLEN], buf[STRLEN];
int ndomains = 0;
int nmatch, specid, idom;
float r_upper, r_lower, length;
char *type = buf;
struct domain *dom;
enum domaintypes dtype;
double (*profile_function)();
geometry=fopen(in->datafile,"r");
if (! geometry) {
fatal_error(1, "Failed to open datafile %s.\n",in->datafile);
};
while(fgets(line,STRLEN,geometry)) {
if (line[0] == '#') continue;
nmatch = sscanf(line,"%s %f %f %f %d",type,&r_upper,&r_lower,&length,&specid);
if (nmatch==2) { /* set variables; r_upper always holds the value */
if (!strcmp("RADIUS",type)) in->r_outer = r_upper;
mesg(INPUT,"parameter: %s=%f",type,r_upper);
continue;
} else if (nmatch==3) specid=in->specid;
mesg(INPUT,"domain %2d: %s r_u=%f r_l=%f l=%f specid=%d",
ndomains,type,r_upper,r_lower,length,specid);
/* record type */
if (!strcmp("MOUTH",type)) dtype = MOUTH;
else if (!strcmp("PORE",type)) dtype = PORE;
else if (!strcmp("LAYER",type)) dtype = LAYER;
else {
fatal_error(1,"Unknown domain type %s.\n",type);
}
if (ndomains-1 == MAXDOMAINS) {
fatal_error(1,"Internal limit: only %d domains allowed.\n",MAXDOMAINS);
}
profile_function = (r_lower == r_upper) ? &constant : &linear;
domain_list[ndomains] = ini_domain(dtype, "custom domain", length,
profile_function, &species[specid],
r_upper, r_lower,
NULL,NULL);
ndomains++;
}
/* fix domain linkage (already initialized to NULL) */
if (ndomains > 1) {
domain_list[0].next = &domain_list[1];
for(idom=1;idom<ndomains-1;idom++) {
domain_list[idom].prev = &domain_list[idom-1];
domain_list[idom].next = &domain_list[idom+1];
}
domain_list[ndomains-1].prev = &domain_list[ndomains-2];
domain_list[ndomains-1].next = NULL;
}
return ndomains;
}
struct std_input default_input ()
{
struct std_input this = {
3.5,
8.0,
7.5,
4.0,
15.5,
METHANE,
"pore.pdb",
"pore.itp",
2,
{
{0, DZMIN, DZMAX, 0, 44},
{1, DLMIN, DLMAX, 45, 90}
},
GMX_BOND_C1,
GMX_ANGLE_C1,
FALSE,
FALSE,
FALSE,
NULL /* datafile */
};
return this;
};
int input_geom(struct std_input *in, struct geom *g) {
/* input values for the overall geometry of the pore model */
int i;
static struct domain all_domains[MAXDOMAINS];
if (in->datafile) {
/* read from data file */
g->ndomains = datafile_geom(in, all_domains);
} else { /* simple input from commandline */
g->ndomains = standard_geom(in, all_domains);
}
g->coordfile = in->coordfile;
g->topofile = in->topofile;
g->r_outer = in->r_outer; /* can be set from datafile */
g->nbc = in->n_bc;
g->bc = in->bc;
g->k_bond = in->k_bond;
g->k_angle = in->k_angle;
g->connectonly = in->connectonly;
g->atomsonly = in->atomsonly;
g->shiftcbox = in->shiftcbox;
for (i = 0; i < g->ndomains && i < MAXDOMAINS; i++)
{
g->domain[i] = &all_domains[i];
/* set r_outer also in each domain. Redundant, but more
convenient because then all domain information is in one
place
Kludge...
*/
g->domain[i]->r_outer = g->r_outer;
g->domain[i]->rho_outer = g->r_outer - g->domain[i]->species->radius;
};
/* initialize to 0 */
g->nsites = 0;
g->nbonds = 0;
/* unitcell struc is filled by unitcell() after setup_domain()*/
return g->ndomains;
};
void setup_domain (struct geom *g) {
/* - double pass setup; PORE regios determine global
inter-layer spacing dz
*/
int i;
double l_pore=0; /* total length of pore region, center-center */
int q_pore; /* number of gaps between layers */
int q_check, nborders, lastborder;
double dz, dA;
double z1, z2;
enum domaintypes lastdtype;
struct domain *dom;
dA = 0.0; /* distance between two atoms ('bond length') */
q_check = 0; /* internal topology check */
nborders = 0; /* number of interfaces between different domains */
lastdtype = g->domain[0]->type;
/* first pass:
total length of pore region and global dz
also check correct topology: MOUTH -> PORE -> MOUTH
*/
for (i = 0; i < g->ndomains; i++) {
dom = g->domain[i];
if (dom->type != lastdtype) {
nborders++; /* increase nborders for each change M<->P */
lastborder = i - 1; /* last PORE region before second MOUTH */
};
lastdtype = dom->type;
if ( dom->type == PORE) {
l_pore += dom->l;
dA = max(dA, 2 * dom->species->radius);
mesg (SUB2, "setup_domain(): l_pore = %6.3f 2*rA = %4.2f", l_pore, dA);
};
};
/* if nborders != 2 => error!! */
if ( nborders != 2 ) {
fatal_error (2,
"setup_domain (): Fatal error. Topology of model is incorrect. It should\n"
" have been MOUTH->PORE->MOUTH with 2 borders, but there\n"
" were %d borders in %d domains", nborders, g->ndomains);
};
q_pore = (int) l_pore/dA;
if ( q_pore < 1 ) {
fatal_error (2,
"setup_domain (): Fatal error. Number of layers in the PORE is not positive\n"
" (q_pore = %d). (l_pore=%4.2f) < (2*rA=%4.2f)\n",
q_pore, l_pore, dA);
};
dz = l_pore/q_pore;
/* second pass:
number of layers q per domain and z coordinates of lower and upper layer
*/
z2 = -dz;
for (i = 0; i < g->ndomains; i++) {
dom = g->domain[i];
if ( dom->type == PORE)
{
dom->q = round (dom->l / dz);
q_check += dom->q;
dom->dz = dz; /* rather pointless to store dz separately
but I still used the old strucs */
}
else
{
dom->q = round (dom->l / dA);
dom->dz = dz; /* pointless ... */
};
if (dom->q < 0) {
fatal_error (2,
"setup_domain (): Fatal error. Number of layers in domain %d "
"is not positive\n"
" (q = %d). Probably (l=%4.2f) < (2*rA=%4.2f)\n",
i,dom->q, dom->l, dA);
};
z1 = z2 + dz;
z2 = z1 + (dom->q - 1) * dz;
dom->z1 = z1;
dom->z2 = z2;
};
assert (q_check == q_pore);
return;
};
int do_coordinates (struct pdb_ATOM *model, struct geom *g)
{
int j;
/* loop over domains */
for (j = 0; j < g->ndomains; j++)
{
g->domain[j]->first_site = (j == 0 ? 0 : g->domain[j-1]->last_site + 1);
g->domain[j]->last_site = do_layer(g->domain[j], model) - 1;
};
/* record number of sites in the model */
g->nsites = g->domain[j-1]->last_site + 1;
assert (g->nsites <= TOTALSITES);
return g->nsites;
};
int do_layer (struct domain *dom, struct pdb_ATOM *model)
{
struct layer curr_layer;
int i, new_site=-1;
double z;
/* loop over layers in domain */
for (i = 0; i < dom->q; i++)
{
z = dom->z1 + i*dom->dz;
curr_layer = setup_layer(z, dom);
print_layer(&curr_layer);
new_site = do_ring(&curr_layer, model);
};
return new_site;
};
struct layer setup_layer (double z, struct domain *d)
{
struct layer l;
double rA, z1, z2, rho1, rho2;
rA = d->species->radius; /* 1/2 interatomic distance (1/2 'bond' length) */
l.rhomax = d->rho_outer;
/* limits for calculating the shape of the wall: continuity
currently quite messy; it should be possible to eliminate rho1/2
in favor for one rho
*/
if (d->prev) {
z1 = d->prev->z2;
rho1 = d->prev->rho2;
} else {
z1 = d->z1;
rho1 = d->rho1;
};
if (d->next) {
z2 = d->next->z1;
rho2 = d->next->rho1;
} else {
z2 = d->z2;
rho2 = d->rho2;
};
/* determine inner radius for this layer at z */
if (d->q > 1) {
/* ie z1 != z2 */
l.rhomin = d->rho(z, z1, z2, rho1, rho2);
} else {
/* degenerate case */
l.rhomin = max(rho1, rho2);
};
assert(l.rhomin <= l.rhomax);
l.z = z;
l.maxring= round (l.rhomax - l.rhomin) / (2 * rA);
/* rounding is not really correct here, but gives better results */
if ( l.maxring == 0) {
/* only enough space for the outermost ring */
l.rhomin = l.rhomax;
};
l.dr = (l.rhomax - l.rhomin) / (double) l.maxring;
l.domain = d;
return l;
}
struct ring setup_ring (double rho, struct layer *l)
{
struct ring this;
this.maxsite = floor(PI/(asin( l->domain->species->radius / rho )));
this.dphi = 2*PI / this.maxsite;
this.rho = rho;
this.layer = l;
return this;
};
int do_ring (struct layer *l, struct pdb_ATOM *model)
{
struct ring curr_ring;
double rho;
int new_site=-1;
for (rho = l->rhomin; rho <= l->rhomax; rho+=(l->dr))
{
curr_ring = setup_ring (rho, l);
/* hack for flagging cavity exposed atoms */
curr_ring.bExposed = (rho == l->rhomin);
print_ring(&curr_ring);
new_site = do_site (&curr_ring, model);
};
return new_site;
};
int do_site (struct ring *r, struct pdb_ATOM *model)
{
static int new_site; /* initialized to 0 by compiler */
struct pdb_ATOM *s;
int i;
/* actually it is completely brain damaged to have string pointers
in the pdb struct; one needs the strings to be somewhere between
fuction calls... anyway, I am using static chars[] for the time being */
static char RES[] = "MTH";
static char EXPOSED[] = "EXPD";
static char EMPTY[1] = "";
char *segment;
Cylindrical u;
/* flag inner wall atoms */
segment = (r->bExposed) ? EXPOSED : EMPTY;
for (i = 0, u.phi = 0; i < r->maxsite; i++, u.phi += r->dphi)
{
s = &model[i + new_site];
s->serial = i + new_site + 1; /* serial is NOT the offset in the array*/
s->species = r->layer->domain->species;
s->name = s->species->symbol;
s->altLoc = " ";
s->resName = RES;
s->chainID = " ";
s->resSeq = 1; /* all pore atomes belong to the same res/chain */
s->iCode = " ";
u.rho = r->rho;
u.z = r->layer->z;
s->cpos = u;
s->pos = cyl2cart(u);
s->occupancy = 0; /* dont care, dont know... */
s->tempFactor = 0;
s->segID = segment;
s->element = " ";
s->charge = s->species->charge;
/* GROMACS atoms section */
/* buffer overflow possible (max length 10): */
/* sprintf (s->atom, "%s%d", s->species->gmx_name, s->serial);
assert (strlen(s->atom) <= 10);
*/
strncpy (s->atom, s->species->gmx_name, 9);
s->cgnr = s->serial;
/* all atoms in their own charge group. Perhaps
better to divide it up into domains, but for
the time being...
*/
print_site(s);
};
return new_site += i; /* first site of next ring */
}
void unitcell (struct geom *g) {
struct pdb_CRYST1 *u;
u = &(g->unitcell);
/* unitcell size */
u->a = u->b = 2 * g->domain[0]->rho_outer;
u->c = fabs (g->domain[g->ndomains - 1]->z2 - g->domain[0]->z1);
/* tetragonal unitcell */
u->alpha = u->beta = u->gamma = 90.00;
u->eGroup = "P 1";
u->z = 1;
return;
};
void cavitybox (struct geom *g) {
/* tetragonal bounding box for the cavity of the pore */
struct pdb_CRYST1 *c;
struct domain *top, *bottom;
c = &(g->cavitybox);
top = g->domain[g->ndomains - 1];
bottom = g->domain[0];
c->a = c->b = 2 * max( max(top->r1, top->r2),
max(bottom->r1, bottom->r2));
c->c = fabs (top->z2 - bottom->z1)
+ top->species->radius + bottom->species->radius;
c->alpha = c->beta = c->gamma = 90.00;
c->eGroup = "P 1";
c->z = 1;
return;
};
/* volume of a domain */
real volume (struct potpars *pp, struct pdb_ATOM model[], struct domain *dom,
struct pprofile *prf) {
real vol, Rmax, zmin, zmax;
real min; /* global (hopefully) minimum in the total potential */
int i,first,last;
/* take all atoms of this and neighboring domains: "Take them
out. All of them!" (Senator Palpartine aka Darth Sidious) */
first = (dom->prev) ? dom->prev->first_site : dom->first_site;
last = (dom->next) ? dom->next->last_site : dom->last_site;
pp->ncenters=last-first + 1;
mesg(SUB1,"volume(): Using %d atoms (%d -> %d), centered on domain '%s'.",
pp->ncenters,first,last,dom->description);
Rmax = (prf->bSet) ? prf->Rmax : dom->rho1/10.0;
zmin=(dom->z1 - dom->dz/2.0)/10.0;
zmax=(dom->z2 + dom->dz/2.0)/10.0;
/* setup the function to be integrated */
/* (1) find the minimum
- requires a function in cartesian coordinates
-> setup the centers in cartesian
- use cartesian vlj()
*/
{
Cartesian pos;
pp->xyzcenters=grid2_alloc(pp->ncenters,3);
for(i=0;i<pp->ncenters;i++) {
pos = cyl2cart(model[i+first].cpos);
pp->xyzcenters[i][XX]=pos.x/10.0;
pp->xyzcenters[i][YY]=pos.y/10.0;
pp->xyzcenters[i][ZZ]=pos.z/10.0;
}
init_vljcyl(pp);
mesg(VERBOSE,"Potential: %s with ffgmx OW-CH4 interaction parameters at T=%g K",
"Lennard-Jones 12-6 V_LJ(x,y,z)", pp->Temp);
pp->min=find_min(vljvec,Rmax,zmin,zmax,NULL);
mesg(VERBOSE,"Minimum: %f\n",pp->min);
}
/* (2) calculate the volume
- this is better done in cylindrical coordinates
--> setup again (and use cylindrical LJ)
*/
/* These cylindrical coordinates are buried in structures; I rather
have them as simple arrays: AND Length has to be in nm (not
Angstrom) because this is the length unit in the Lennard-Jones
parameters (currently CH4-OW hardcoded) */
pp->centers=grid2_alloc(pp->ncenters,3);
for(i=0;i<pp->ncenters;i++) {
pp->centers[i][RAD]=model[i+first].cpos.rho/10.0;
pp->centers[i][PHI]=model[i+first].cpos.phi;
pp->centers[i][ZZZ]=model[i+first].cpos.z/10.0;
}
init_vljcyl(pp); /* now with the minimum found and with the
LJ-centers in cylindrical coordinates! */
mesg(VERBOSE,"Potential: Shifted Lennard-Jones 12-6 V_LJ(r,phi,z) - %g kT "
"with ffgmx OW-CH4 interaction parameters at T=%g K", pp->min, pp->Temp);
init_gaussleg(pp->ngaussleg);
mesg(VERBOSE,"Using %d-point Gauss-Legendre quadrature for the volume integrals.",
pp->ngaussleg);
if (prf->bPlot) plot_potential(vljcyl,Rmax,zmin,zmax,prf->nzplot);
/*
mesg(VERBOSE,"Potential: %s with ffgmx OW-CH4 interaction parameters",
(prf->pot == vRljcyl) ? "WCA repulsive V_R,LJ(r)" : "Lennard-Jones 12-6 V_LJ(r)");
*/
#ifdef TESTCASE
{
real vexact;
/* test case: this should give the exact volume */
mesg(SUB1,"-------> Internal test of volume integration <-------");
vexact=PI*Rmax*Rmax*(zmax-zmin);
mesg(SUB1,"VOLUME_TEST: R[nm] <%f> R_c[nm] <%f> L[nm] <%f> V=¶·R_c²·L[nm³] <%f>",
dom->r1/10.0, Rmax, zmax-zmin, vexact);
vol=cylint(cylconst, 0,Rmax, 0, 2*PI, zmin,zmax);
mesg(SUB1,"VOLUME_TEST: f=1: Volume <%f> V_exact <%f>", vol,vexact);
vol=cylint(cylcos, 0,Rmax, 0, 2*PI, zmin,zmax);
vexact=0;
mesg(SUB1,"VOLUME_TEST: f=cos(phi): Volume <%f> V_exact <%f>", vol,vexact);
vol=cylint(cyl3, 0,Rmax, 0, 2*PI, 0,zmax-zmin);
vexact=(1-exp(-Rmax))*PI*pow(zmax-zmin,3)/3.0;
mesg(SUB1,"VOLUME_TEST: f=1/r exp(-r)*cos(phi)*cos(phi)*z: Volume <%f> V_exact <%f>",
vol,vexact);
vexact=1.0; /* PI*Rmax*Rmax*(zmax-zmin); */
vol = tdavg(Qvol,Zero, Rmax,zmin,zmax);
mesg(SUB1,"VOLUME_TEST: <Qvol>, V(r)=0: Volume <%f> V_exact <%f>",
vol,vexact);
/* this analytical soln is alraedy specialised for FHG=6 */
vexact=(1.0-4.0*exp(-3.0))/(1-exp(-6.0*Rmax)*(1.0+6.0*Rmax));
vol = tdavg(Qvol,LinCheck, Rmax,zmin,zmax);
mesg(SUB1,"VOLUME_TEST: <Qvol>, V(r)=6r: Volume <%f> V_exact <%f>",
vol,vexact);
/* correct one, f = 6, gives the same as above */
#define FHG 6.0
vexact= -(exp(FHG*(-0.5 + Rmax))*
(-2.0 + 2.0*exp(FHG/2.) - FHG))/ (2.*(1.0 - exp(FHG*Rmax) + FHG*Rmax));
vol = tdavg(Qvol,LinCheck, Rmax,zmin,zmax);
mesg(SUB1,"VOLUME_TEST: <Qvol>, V(r)=f/beta r nm^-1: Volume <%f> V_exact <%f>",
vol,vexact);
/* g(E) * exp(-bE) * f()
f(r) = K1/2 r^2 (integral from Mathematica)
*/
vexact=2.0*PI*(zmax-zmin)*
(K1*pow(Rmax,2) - (3.0*sqrt(2.0/PI)*sqrt(K1*pow(Rmax,2)))/
exp((K1*pow(Rmax,2))/2.) +
(3.0 - K1*pow(Rmax,2))*
erf(sqrt(K1*pow(Rmax,2))/sqrt(2)))/(2.*K1);
vol = xV(harmonic,Rmax,zmin,zmax);
mesg(SUB1,"VOLUME_TEST: xV: V(r)= k/2b r² nm^-1: Volume <%f> V_exact <%f>",
vol,vexact);
mesg(SUB1,"------> End of testcases <-------\n");
}
#endif /* TESTCASE */
/* total volume */
/* simple & inefficient (two integrations):
V = <Q> = Tr Qexp(-beta H) / Tr exp(-beta H)
*/
mesg(INPUT,"VOLUME_INPUT: R[nm] <%f> R_c[nm] <%f> L[nm] <%f> V=¶·R_c²·L[nm³] <%f>",
dom->r1/10.0, Rmax, zmax-zmin, PI*Rmax*Rmax*(zmax-zmin));
mesg(INPUT,"VOLUME_PARAMETERS: Rmax[nm] <%f> z1 <%f> z2 <%f>",Rmax,zmin, zmax);
/* accessible volume, Labbook II, p84 */
vol = xV(vljshiftcyl,Rmax,zmin,zmax);
mesg(INPUT,"VOLUME_DATA: xV Volume[nm³] <%f> R*[nm] <%f>\n",
vol,sqrt(vol/(PI*(zmax-zmin))));
/* normalised configurational volume, Labbok II, p79 (rubbish!) */
vol = Zsum(vljshiftcyl,Rmax,zmin,zmax);
mesg(INPUT,"VOLUME_DATA: v1/Z Volume[nm³] <%f> R*[nm] <%f>\n",
vol,sqrt(vol/(PI*(zmax-zmin))));
/* Thermodynamic average at fixed particle energy, Labbook II, p78 */
/* vol = tdavg(Qvol,prf->pp->u1, Rmax,zmin,zmax); */
/* mesg(INPUT,"VOLUME_DATA: <Qvol> Volume[nm³] <%f> R*[nm] <%f>\n", */
/* vol,sqrt(vol/(PI*(zmax-zmin)))); */
/* Pure configurational volume (unnormalised) */
/* vol = cylint(Z_V, 0,Rmax, 0,2*PI, zmin,zmax); */
/* mesg(INPUT,"VOLUME_DATA: v1 Volume[nm³] <%f> R*[nm] <%f>\n", */
/* vol,sqrt(vol/(PI*(zmax-zmin)))); */
if (prf->bSet) calc_profile(prf);
free_gaussleg();
free(pp->centers);
free(pp->xyzcenters);
return vol;
}
/* pore profile
calculate the effective radius in thin slices, spaced by dz
*/
void calc_profile (struct pprofile *prf) {
int i;
real deltaZ;
real Rmax=prf->Rmax;
real zmin=prf->z1;
real zmax=prf->z2;
mesg(VERBOSE,"Calculating pore profile (%d z-slices)",prf->nz);
mesg(INPUT,"pore profile: Rmax <%f> zmin <%f> zmax <%f> [nm]",
Rmax,zmin,zmax);
prf->r=grid2_alloc(prf->nz,2);
deltaZ = (zmax - zmin)/(real)prf->nz;
for(i=0;i<prf->nz;i++) {
fprintf(stderr,"\rIntegrating slice %6d (z=%2.3fnm) [%5.1f%%] ",
i,zmin+(i+0.5)*deltaZ,((real)i+1.0)*100/(real)prf->nz);
prf->r[i][0]=zmin + (i+0.5)*deltaZ;
prf->r[i][1]=sqrt(
xV(vljshiftcyl, Rmax, zmin+i*deltaZ, zmin+(i+1)*deltaZ) / (PI*deltaZ) );
}
fprintf(stderr,"\n");
return;
}
/* append int+1 levels (upto value max) to the file */
void xf_append_levels (FILE *fData, int ncols, real min, real max) {
int i;
real delta;
delta = (max-min)/(ncols);
fprintf(fData,"%d\n",ncols); /* number of levels */
for(i=1;i<=ncols;i++) /* equally spaced */
fprintf(fData, "%d %f\n",i,min+i*delta);
return;
}
void xf_append_axes_annotation (FILE *fData, real x1, real x2,
real y1, real y2) {
fprintf(fData,"%f %f\n",x1, x2);
fprintf(fData,"%f %f\n",y1, y2);
return;
}
/* plot the potential (xfarbe format) */
void plot_potential (real (*f)(real,real,real),real Rmax,real zmin, real zmax,
int nslices) {
int i,j,k;
char buf[STRLEN];
char *fn = buf;
FILE *XF;
real xmin,xmax,ymin,ymax,dx,dy,dz;
real x,y,z;
int nx,ny,nz;
#define XF_RES 0.01 /* nm */
xmin=ymin=-Rmax;
xmax=ymax=Rmax;
zmin -= 0.5;
zmax += 0.5;
nx = (int)((xmax-xmin)/XF_RES)+1;
dx=XF_RES;
ny = (int)((ymax-ymin)/XF_RES)+1;
dy=XF_RES;
nz = nslices;
dz=(zmax-zmin)/nslices;
for(k=0; k<nslices;k++) {
z=zmin+k*dz;
sprintf(fn,"xy_%03d.dat",k);
XF=fopen(fn,"w");
mesg(VERBOSE,"Writing potential at z=%f into %s",z,fn);
fprintf(XF,"LJ-potential at z=%f\n",z);
fprintf(XF,"%d %d\n",nx,ny);
for(j=0;j<ny;j++){
y=ymin+j*dy;
for(i=0;i<nx;i++) {
x=xmin+i*dx;
fprintf(XF,"%f ",f(sqrt(x*x+y*y),atan2(y,x),z));
}
fprintf(XF,"\n");
}
xf_append_levels(XF,32,-2,4);
xf_append_axes_annotation(XF,xmin,xmax,ymin,ymax);
fclose(XF);
}
/* same thing again for xz */
nx = (int)((xmax-xmin)/XF_RES)+1;
dx=XF_RES;
ny = nslices;
dy=(ymax-ymin)/nslices;
nz = (int)((zmax-zmin)/XF_RES)+1;
dz=XF_RES;
for(j=0;j<nslices;j++){
y=ymin+j*dy;
sprintf(fn,"xz_%03d.dat",j);
XF=fopen(fn,"w");
mesg(VERBOSE,"Writing potential at y=%f into %s",y,fn);
fprintf(XF,"LJ-potential at y=%f\n",y);
fprintf(XF,"%d %d\n",nx,nz);
for(k=0; k<nz;k++) {
z=zmin+k*dz;
for(i=0;i<nx;i++) {
x=xmin+i*dx;
fprintf(XF,"%f ",f(sqrt(x*x+y*y),atan2(y,x),z));
}
fprintf(XF,"\n");
}
xf_append_levels(XF,32,-2,4);
xf_append_axes_annotation(XF,xmin,xmax,ymin,ymax);
fclose(XF);
}
}
int pdb_write_header (FILE *fp, struct geom *g)
{
int i, error;
struct pdb_HEADER h = {
"Atomistic Model for a Transmembrane Channel",
" ",
" "
};
struct pdb_REMARK r = {
6,
""
};
struct domain *d;
error = pdb_w_header (fp, &h);
for (i = 0; i < g->ndomains && i <= MAXDOMAINS; i++)
{
/* basically print_domain () */
d = g->domain[i];
sprintf (r.remark, " Type %d: %s", d->type, d->description);
error = pdb_w_remark (fp, &r);
mesg (SUB1, "writing... [%s]", r.remark);
sprintf (r.remark, " Defaultspecies %s <%s> rA <%4.2f> charge <%-2s>",
d->species->name, d->species->symbol, d->species->radius,
d->species->charge);
error = pdb_w_remark (fp, &r);
sprintf (r.remark, " Length <%6.3f> r1 <%6.3f> r2 <%6.3f> r_outer <%6.3f>",
d->l, d->r1, d->r2, d->r_outer);
error = pdb_w_remark (fp, &r);
sprintf (r.remark, " rho1 <%6.3f> rho2 <%6.3f> rho_outer <%6.3f>",
d->rho1, d->rho2, d->rho_outer);
error = pdb_w_remark (fp, &r);
sprintf (r.remark, " z1 <%6.3f> z2 <%6.3f> Delta_z <%6.3f> q <%d>",
d->z1, d->z2, d->dz, d->q);
error = pdb_w_remark (fp, &r);
sprintf (r.remark, " first_site <%d> last_site <%d>",
d->first_site, d->last_site);
error = pdb_w_remark (fp, &r);
};
return error;
};
void print_geom(struct geom *g)
{
int i;
if (debuglevel <= OFF) return;
printf("Geometry data\nR_outer <%5.2f> N_domains <%d> N_sites <%d> N_bonds <%d> \n",
g->r_outer, g->ndomains, g->nsites, g->nbonds);
printf("--------------------------------------------------------------------\n");
if (debuglevel < INPUT) return;
for (i = 0; i < g->ndomains && i <= MAXDOMAINS; i++)
{
print_domain(g->domain[i]);
};
printf("\n");
return;
};
void print_domain (struct domain *d)
{
if (debuglevel < INPUT) return;
printf(" Type %d: %s\n", d->type, d->description);
printf(" Defaultspecies %s <%s> rA <%4.2f> charge <%-2s>\n",
d->species->name, d->species->symbol, d->species->radius,
d->species->charge);
printf(" Length <%6.3f> r1 <%6.3f> r2 <%6.3f> r_outer <%6.3f>\n",