7 |
|
#include "simError.h" |
8 |
|
#include "SimInfo.hpp" |
9 |
|
#include "ReadWrite.hpp" |
10 |
+ |
#include "SimSetup.hpp" |
11 |
|
|
12 |
|
#include "MoLocator.hpp" |
13 |
|
#include "latticeBuilder.hpp" |
13 |
– |
#include "QuickBass.hpp" |
14 |
|
|
15 |
+ |
|
16 |
|
#define VERSION_MAJOR 0 |
17 |
|
#define VERSION_MINOR 1 |
18 |
|
|
20 |
|
void usage(void); |
21 |
|
int buildLatticeBilayer( double aLat, |
22 |
|
double bLat, |
23 |
< |
double leafSpacing); |
23 |
> |
double leafSpacing, |
24 |
> |
char* waterName, |
25 |
> |
char* lipidName); |
26 |
|
using namespace std; |
27 |
+ |
SimInfo* mainInfo; |
28 |
|
|
29 |
|
int main(int argC,char* argV[]){ |
30 |
|
|
48 |
|
double aLat, bLat, leafSpacing; |
49 |
|
|
50 |
|
char* inName; |
51 |
+ |
|
52 |
+ |
SimSetup* simInit; |
53 |
|
|
54 |
|
// first things first, all of the initializations |
55 |
|
|
286 |
|
simError(); |
287 |
|
} |
288 |
|
|
289 |
< |
bLat = strtod( argV[i], &conversionCheck); |
290 |
< |
if( conversionCheck == argV[i] ) conversionError = true; |
291 |
< |
if( *conversionCheck != '\0' ) conversionError = true; |
289 |
> |
|
290 |
> |
bLat = atof( argV[i] ); |
291 |
> |
// bLat = strtod( argV[i], &conversionCheck); |
292 |
> |
// if( conversionCheck == argV[i] ) conversionError = true; |
293 |
> |
// if( *conversionCheck != '\0' ) conversionError = true; |
294 |
|
|
295 |
|
if( conversionError ){ |
296 |
|
sprintf( painCave.errMsg, |
336 |
|
simError(); |
337 |
|
} |
338 |
|
|
339 |
< |
aLat = strtod( argV[i], &conversionCheck); |
340 |
< |
if( conversionCheck == argV[i] ) conversionError = true; |
341 |
< |
if( *conversionCheck != '\0' ) conversionError = true; |
339 |
> |
aLat = atof( argV[i] ); |
340 |
> |
// aLat = strtod( argV[i], &conversionCheck); |
341 |
> |
// if( conversionCheck == argV[i] ) conversionError = true; |
342 |
> |
// if( *conversionCheck != '\0' ) conversionError = true; |
343 |
|
|
344 |
|
if( conversionError ){ |
345 |
|
sprintf( painCave.errMsg, |
383 |
|
simError(); |
384 |
|
} |
385 |
|
|
386 |
< |
bLat = strtod( argV[i], &conversionCheck); |
387 |
< |
if( conversionCheck == argV[i] ) conversionError = true; |
388 |
< |
if( *conversionCheck != '\0' ) conversionError = true; |
386 |
> |
bLat = atof( argV[i] ); |
387 |
> |
|
388 |
> |
// bLat = strtod( argV[i], &conversionCheck); |
389 |
> |
// if( conversionCheck == argV[i] ) conversionError = true; |
390 |
> |
// if( *conversionCheck != '\0' ) conversionError = true; |
391 |
|
|
392 |
|
if( conversionError ){ |
393 |
|
sprintf( painCave.errMsg, |
431 |
|
simError(); |
432 |
|
} |
433 |
|
|
434 |
< |
leafSpacing = strtod( argV[i], &conversionCheck); |
435 |
< |
if( conversionCheck == argV[i] ) conversionError = true; |
436 |
< |
if( *conversionCheck != '\0' ) conversionError = true; |
434 |
> |
leafSpacing = atof( argV[i] ); |
435 |
> |
|
436 |
> |
// leafSpacing = strtod( argV[i], &conversionCheck); |
437 |
> |
// if( conversionCheck == argV[i] ) conversionError = true; |
438 |
> |
// if( *conversionCheck != '\0' ) conversionError = true; |
439 |
|
|
440 |
|
if( conversionError ){ |
441 |
|
sprintf( painCave.errMsg, |
544 |
|
simError(); |
545 |
|
} |
546 |
|
|
547 |
< |
bsInfo.outPrefix = outPrefix; |
548 |
< |
strcpy(bsInfo.waterName, waterName); |
549 |
< |
strcpy(bsInfo.lipidName, lipidName); |
547 |
> |
mainInfo = new SimInfo(); |
548 |
> |
simInit = new SimSetup(); |
549 |
> |
simInit->setSimInfo( mainInfo ); |
550 |
> |
simInit->suspendInit(); |
551 |
> |
simInit->parseFile( inName ); |
552 |
> |
simInit->createSim(); |
553 |
|
|
554 |
< |
parseBuildBass( inName ); |
554 |
> |
delete simInit; |
555 |
|
|
556 |
< |
buildLatticeBilayer( aLat, bLat, leafSpacing ); |
556 |
> |
sprintf( mainInfo->statusName, "%s.stat", outPrefix ); |
557 |
> |
sprintf( mainInfo->sampleName, "%s.dump", outPrefix ); |
558 |
> |
sprintf( mainInfo->finalName, "%s.init", outPrefix ); |
559 |
|
|
560 |
+ |
buildLatticeBilayer( aLat, bLat, leafSpacing, waterName, lipidName ); |
561 |
+ |
|
562 |
|
return 0; |
563 |
|
} |
564 |
|
|
565 |
|
int buildLatticeBilayer(double aLat, |
566 |
|
double bLat, |
567 |
< |
double leafSpacing){ |
567 |
> |
double leafSpacing, |
568 |
> |
char* waterName, |
569 |
> |
char* lipidName){ |
570 |
|
|
571 |
|
typedef struct{ |
572 |
|
double rot[3][3]; |
581 |
|
double *posX, *posY, *posZ; |
582 |
|
double pos[3], posA[3], posB[3]; |
583 |
|
|
584 |
< |
const double waterFudge = 5.0; |
584 |
> |
const double waterFudge = 6.0; |
585 |
|
|
586 |
|
int i,j,k,l; |
587 |
|
int nAtoms, atomIndex, molIndex, molID; |
592 |
|
int nCells, nCellsX, nCellsY, nCellsZ; |
593 |
|
int nx, ny; |
594 |
|
double boxX, boxY, boxZ; |
595 |
< |
double unitVector[3]; |
595 |
> |
double theta, phi, psi; |
596 |
|
int which; |
597 |
|
int targetWaters; |
598 |
|
|
599 |
|
Atom** atoms; |
578 |
– |
SimInfo* simnfo; |
600 |
|
SimInfo* testInfo; |
601 |
|
coord testSite; |
602 |
|
SimState* theConfig; |
612 |
|
double targetWaterLipidRatio; |
613 |
|
double maxZ, minZ, zHeight; |
614 |
|
|
615 |
< |
// create the simInfo objects |
615 |
> |
molStart = NULL; |
616 |
|
|
596 |
– |
simnfo = new SimInfo; |
597 |
– |
|
617 |
|
// set the the lipidStamp |
618 |
|
|
619 |
|
foundLipid = 0; |
620 |
|
foundWater = 0; |
621 |
< |
for(i=0; i<bsInfo.nComponents; i++){ |
622 |
< |
if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.lipidName ) ){ |
621 |
> |
|
622 |
> |
for(i=0; i<mainInfo->nComponents; i++){ |
623 |
> |
|
624 |
> |
if( !strcmp( mainInfo->compStamps[i]->getID(), lipidName ) ){ |
625 |
|
|
626 |
|
foundLipid = 1; |
627 |
< |
lipidStamp = bsInfo.compStamps[i]; |
628 |
< |
targetNlipids = bsInfo.componentsNmol[i]; |
627 |
> |
lipidStamp = mainInfo->compStamps[i]; |
628 |
> |
targetNlipids = mainInfo->componentsNmol[i]; |
629 |
|
lipidNatoms = lipidStamp->getNAtoms(); |
630 |
|
} |
631 |
< |
if( !strcmp( bsInfo.compStamps[i]->getID(), bsInfo.waterName ) ){ |
631 |
> |
if( !strcmp( mainInfo->compStamps[i]->getID(), waterName ) ){ |
632 |
|
|
633 |
|
foundWater = 1; |
634 |
|
|
635 |
< |
waterStamp = bsInfo.compStamps[i]; |
636 |
< |
targetNwaters = bsInfo.componentsNmol[i]; |
635 |
> |
waterStamp = mainInfo->compStamps[i]; |
636 |
> |
targetNwaters = mainInfo->componentsNmol[i]; |
637 |
|
waterNatoms = waterStamp->getNAtoms(); |
638 |
|
} |
639 |
|
} |
640 |
|
if( !foundLipid ){ |
641 |
|
sprintf(painCave.errMsg, |
642 |
< |
"Could not find lipid \"%s\" in the bass file.\n", |
643 |
< |
bsInfo.lipidName ); |
642 |
> |
"latticeBilayer error: Could not find lipid \"%s\" in the bass file.\n", |
643 |
> |
lipidName ); |
644 |
|
painCave.isFatal = 1; |
645 |
|
simError(); |
646 |
|
} |
647 |
|
if( !foundWater ){ |
648 |
|
sprintf(painCave.errMsg, |
649 |
< |
"Could not find solvent \"%s\" in the bass file.\n", |
650 |
< |
bsInfo.waterName ); |
649 |
> |
"latticeBilayer error: Could not find solvent \"%s\" in the bass file.\n", |
650 |
> |
waterName ); |
651 |
|
painCave.isFatal = 1; |
652 |
|
simError(); |
653 |
|
} |
670 |
|
testSite.pos[1] = 0.0; |
671 |
|
testSite.pos[2] = 0.0; |
672 |
|
|
673 |
< |
unitVector[0] = 0.0; |
674 |
< |
unitVector[1] = 0.0; |
675 |
< |
unitVector[2] = 1.0; |
676 |
< |
|
677 |
< |
getUnitRot(unitVector, testSite.rot ); |
673 |
> |
theta = 0.0; |
674 |
> |
phi = 0.0; |
675 |
> |
psi = 0.0; |
676 |
> |
|
677 |
> |
getEulerRot(theta, phi, psi, testSite.rot ); |
678 |
|
lipidLocate->placeMol( testSite.pos, testSite.rot, atoms, 0, theConfig ); |
679 |
|
|
680 |
|
minZ = 0.0; |
687 |
|
} |
688 |
|
zHeight = maxZ - minZ; |
689 |
|
|
690 |
< |
nCells = (int) sqrt( (double)targetNlipids * bLat / (4.0 * aLat) ); |
690 |
> |
std::cerr << "aLat = " << aLat << "; bLat = " << bLat << "\n"; |
691 |
|
|
692 |
+ |
nCells = (int)ceil( sqrt( (double)targetNlipids * bLat / (4.0 * aLat) )); |
693 |
+ |
|
694 |
|
nx = nCells; |
695 |
|
ny = (int) ((double)nCells * aLat / bLat); |
696 |
|
|
697 |
+ |
std::cerr << "nx = " << nx << "; ny = " << ny << "\n"; |
698 |
+ |
|
699 |
|
boxX = nx * aLat; |
700 |
|
boxY = ny * bLat; |
701 |
|
|
702 |
|
nLipids = 4 * nx * ny; |
703 |
|
coord* lipidSites = new coord[nLipids]; |
704 |
|
|
705 |
< |
unitVector[0] = 0.0; |
706 |
< |
unitVector[1] = 0.0; |
705 |
> |
phi = 0.0; |
706 |
> |
psi = 0.0; |
707 |
|
|
708 |
|
which = 0; |
709 |
|
|
713 |
|
|
714 |
|
lipidSites[which].pos[0] = (double)i * aLat; |
715 |
|
lipidSites[which].pos[1] = (double)j * bLat; |
716 |
< |
lipidSites[which].pos[2] = ((double)k - 0.5) * (leafSpacing - maxZ); |
716 |
> |
lipidSites[which].pos[2] = (2.0* (double)k - 1.0) * |
717 |
> |
((leafSpacing / 2.0) - maxZ); |
718 |
|
|
719 |
< |
unitVector[2] = 2.0 * (double)k - 1.0; |
719 |
> |
theta = (1.0 - (double)k) * M_PI; |
720 |
|
|
721 |
< |
getUnitRot( unitVector, lipidSites[which].rot ); |
721 |
> |
getEulerRot( theta, phi, psi, lipidSites[which].rot ); |
722 |
|
|
723 |
|
which++; |
724 |
|
|
725 |
|
lipidSites[which].pos[0] = aLat * ((double)i + 0.5); |
726 |
|
lipidSites[which].pos[1] = bLat * ((double)j + 0.5); |
727 |
< |
lipidSites[which].pos[2] = ((double)k - 0.5) * (leafSpacing - maxZ); |
727 |
> |
lipidSites[which].pos[2] = (2.0* (double)k - 1.0) * |
728 |
> |
((leafSpacing / 2.0) - maxZ); |
729 |
|
|
730 |
< |
unitVector[2] = 2.0 * (double)k - 1.0; |
730 |
> |
theta = (1.0 - (double)k) * M_PI; |
731 |
|
|
732 |
< |
getUnitRot( unitVector, lipidSites[which].rot ); |
732 |
> |
getEulerRot( theta, phi, psi, lipidSites[which].rot ); |
733 |
|
|
734 |
|
which++; |
735 |
|
} |
756 |
|
} |
757 |
|
|
758 |
|
nWaters = nCellsX * nCellsY * nCellsZ * 4; |
759 |
+ |
|
760 |
+ |
// calc current system size; |
761 |
+ |
|
762 |
+ |
nAtoms = 0; |
763 |
+ |
molIndex = 0; |
764 |
+ |
if(molStart != NULL ) delete[] molStart; |
765 |
+ |
molStart = new int[nLipids]; |
766 |
+ |
|
767 |
+ |
for(j=0; j<nLipids; j++){ |
768 |
+ |
molStart[molIndex] = nAtoms; |
769 |
+ |
molIndex++; |
770 |
+ |
nAtoms += lipidNatoms; |
771 |
+ |
} |
772 |
+ |
|
773 |
+ |
testInfo->n_atoms = nAtoms; |
774 |
+ |
theConfig = testInfo->getConfiguration(); |
775 |
+ |
theConfig->destroyArrays(); |
776 |
+ |
theConfig->createArrays( nAtoms ); |
777 |
+ |
testInfo->atoms = new Atom*[nAtoms]; |
778 |
+ |
atoms = testInfo->atoms; |
779 |
+ |
|
780 |
+ |
molIndex = 0; |
781 |
+ |
for(i=0; i<nLipids; i++ ){ |
782 |
+ |
lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms, |
783 |
+ |
molStart[molIndex], theConfig ); |
784 |
+ |
molIndex++; |
785 |
+ |
} |
786 |
+ |
|
787 |
+ |
atoms[0]->getPos( myPos ); |
788 |
+ |
|
789 |
+ |
maxZ = myPos[2]; |
790 |
+ |
minZ = myPos[2]; |
791 |
+ |
|
792 |
+ |
for(i=0;i<nAtoms;i++){ |
793 |
+ |
atoms[i]->getPos( myPos ); |
794 |
+ |
|
795 |
+ |
minZ = (minZ > myPos[2]) ? myPos[2] : minZ; |
796 |
+ |
maxZ = (maxZ < myPos[2]) ? myPos[2] : maxZ; |
797 |
+ |
} |
798 |
+ |
|
799 |
+ |
boxZ = (maxZ - minZ)+2.0; |
800 |
+ |
|
801 |
+ |
double centerX, centerY, centerZ; |
802 |
|
|
803 |
+ |
centerX = (boxX / 2.0); |
804 |
+ |
centerY = (boxY / 2.0); |
805 |
+ |
centerZ = ((maxZ - minZ) / 2.0) + minZ; |
806 |
+ |
|
807 |
+ |
// set up water coordinates |
808 |
+ |
|
809 |
|
coord* waterSites = new coord[nWaters]; |
810 |
|
|
811 |
|
waterCell[0] = boxX / nCellsX; |
814 |
|
|
815 |
|
Lattice *myORTHO; |
816 |
|
myORTHO = new Lattice( ORTHORHOMBIC_LATTICE_TYPE, waterCell); |
817 |
< |
myORTHO->setStartZ( leafSpacing / 2.0 + waterFudge); |
817 |
> |
myORTHO->setStartZ( maxZ + waterFudge); |
818 |
|
|
743 |
– |
boxZ = waterCell[2] * nCellsZ + leafSpacing; |
744 |
– |
|
819 |
|
// create an fcc lattice in the water box. |
820 |
|
|
821 |
|
which = 0; |
828 |
|
waterSites[which].pos[0] = posX[l]; |
829 |
|
waterSites[which].pos[1] = posY[l]; |
830 |
|
waterSites[which].pos[2] = posZ[l]; |
831 |
+ |
getRandomRot( waterSites[which].rot ); |
832 |
|
which++; |
833 |
|
} |
834 |
|
} |
835 |
|
} |
836 |
|
} |
837 |
|
|
838 |
< |
// create the real Atom arrays |
838 |
> |
// calc the system sizes |
839 |
|
|
840 |
|
nAtoms = 0; |
841 |
|
molIndex = 0; |
842 |
+ |
if(molStart != NULL ) delete[] molStart; |
843 |
|
molStart = new int[nLipids + nWaters]; |
844 |
|
|
845 |
|
for(j=0; j<nLipids; j++){ |
854 |
|
nAtoms += waterNatoms; |
855 |
|
} |
856 |
|
|
857 |
< |
theConfig = simnfo->getConfiguration(); |
857 |
> |
testInfo->n_atoms = nAtoms; |
858 |
> |
theConfig = testInfo->getConfiguration(); |
859 |
> |
theConfig->destroyArrays(); |
860 |
|
theConfig->createArrays( nAtoms ); |
861 |
< |
simnfo->atoms = new Atom*[nAtoms]; |
862 |
< |
atoms = simnfo->atoms; |
861 |
> |
testInfo->atoms = new Atom*[nAtoms]; |
862 |
> |
atoms = testInfo->atoms; |
863 |
|
|
864 |
+ |
molIndex = 0; |
865 |
+ |
for(i=0; i<nLipids; i++ ){ |
866 |
+ |
lipidLocate->placeMol( lipidSites[i].pos, lipidSites[i].rot, atoms, |
867 |
+ |
molStart[molIndex], theConfig ); |
868 |
+ |
molIndex++; |
869 |
+ |
} |
870 |
|
|
871 |
+ |
for(i=0; i<nWaters; i++){ |
872 |
+ |
|
873 |
+ |
getRandomRot( waterSites[i].rot ); |
874 |
+ |
waterLocate->placeMol( waterSites[i].pos, waterSites[i].rot, atoms, |
875 |
+ |
molStart[molIndex], theConfig ); |
876 |
+ |
molIndex++; |
877 |
+ |
} |
878 |
+ |
|
879 |
+ |
atoms[0]->getPos( myPos ); |
880 |
+ |
maxZ = myPos[2]; |
881 |
+ |
minZ = myPos[2]; |
882 |
+ |
for(i=0;i<nAtoms;i++){ |
883 |
+ |
atoms[i]->getPos( myPos ); |
884 |
+ |
minZ = (minZ > myPos[2]) ? myPos[2] : minZ; |
885 |
+ |
maxZ = (maxZ < myPos[2]) ? myPos[2] : maxZ; |
886 |
+ |
} |
887 |
+ |
boxZ = (maxZ - (minZ - waterFudge / 2.0)); |
888 |
+ |
|
889 |
+ |
// create the real Atom arrays |
890 |
+ |
|
891 |
+ |
delete[] (mainInfo->atoms); |
892 |
+ |
theConfig = mainInfo->getConfiguration(); |
893 |
+ |
theConfig->createArrays( nAtoms ); |
894 |
+ |
mainInfo->atoms = new Atom*[nAtoms]; |
895 |
+ |
mainInfo->n_atoms = nAtoms; |
896 |
+ |
atoms = mainInfo->atoms; |
897 |
+ |
|
898 |
|
// wrap back to <0,0,0> as center |
899 |
|
|
900 |
|
double Hmat[3][3]; |
911 |
|
Hmat[2][1] = 0.0; |
912 |
|
Hmat[2][2] = boxZ; |
913 |
|
|
914 |
< |
bsInfo.boxX = boxX; |
804 |
< |
bsInfo.boxY = boxY; |
805 |
< |
bsInfo.boxZ = boxZ; |
806 |
< |
|
807 |
< |
simnfo->setBoxM( Hmat ); |
914 |
> |
mainInfo->setBoxM( Hmat ); |
915 |
|
|
916 |
< |
for(j=0;j<nLipids;j++) |
810 |
< |
simnfo->wrapVector( lipidSites[j].pos ); |
916 |
> |
for(j=0;j<nLipids;j++){ |
917 |
|
|
918 |
< |
for(j=0;j<nWaters;j++) |
919 |
< |
simnfo->wrapVector( waterSites[j].pos ); |
918 |
> |
lipidSites[j].pos[0] -= centerX; |
919 |
> |
lipidSites[j].pos[1] -= centerY; |
920 |
> |
lipidSites[j].pos[2] -= centerZ; |
921 |
|
|
922 |
+ |
mainInfo->wrapVector( lipidSites[j].pos ); |
923 |
+ |
} |
924 |
+ |
|
925 |
+ |
for(j=0;j<nWaters;j++){ |
926 |
+ |
|
927 |
+ |
waterSites[j].pos[0] -= centerX; |
928 |
+ |
waterSites[j].pos[1] -= centerY; |
929 |
+ |
waterSites[j].pos[2] -= centerZ; |
930 |
+ |
|
931 |
+ |
mainInfo->wrapVector( waterSites[j].pos ); |
932 |
+ |
} |
933 |
+ |
|
934 |
|
// initialize lipid positions |
935 |
|
|
936 |
|
molIndex = 0; |
943 |
|
// initialize the water positions |
944 |
|
|
945 |
|
for(i=0; i<nWaters; i++){ |
946 |
< |
|
946 |
> |
|
947 |
|
getRandomRot( waterSites[i].rot ); |
948 |
|
waterLocate->placeMol( waterSites[i].pos, waterSites[i].rot, atoms, |
949 |
|
molStart[molIndex], theConfig ); |
950 |
|
molIndex++; |
951 |
|
} |
952 |
|
|
834 |
– |
// set up the SimInfo object |
835 |
– |
|
836 |
– |
Hmat[0][0] = boxX; |
837 |
– |
Hmat[0][1] = 0.0; |
838 |
– |
Hmat[0][2] = 0.0; |
839 |
– |
|
840 |
– |
Hmat[1][0] = 0.0; |
841 |
– |
Hmat[1][1] = boxY; |
842 |
– |
Hmat[1][2] = 0.0; |
843 |
– |
|
844 |
– |
Hmat[2][0] = 0.0; |
845 |
– |
Hmat[2][1] = 0.0; |
846 |
– |
Hmat[2][2] = boxZ; |
847 |
– |
|
848 |
– |
|
849 |
– |
bsInfo.boxX = boxX; |
850 |
– |
bsInfo.boxY = boxY; |
851 |
– |
bsInfo.boxZ = boxZ; |
852 |
– |
|
853 |
– |
simnfo->setBoxM( Hmat ); |
854 |
– |
|
855 |
– |
sprintf( simnfo->sampleName, "%s.dump", bsInfo.outPrefix ); |
856 |
– |
sprintf( simnfo->finalName, "%s.init", bsInfo.outPrefix ); |
857 |
– |
|
953 |
|
// set up the writer and write out |
954 |
|
|
955 |
< |
writer = new DumpWriter( simnfo ); |
955 |
> |
writer = new DumpWriter( mainInfo ); |
956 |
|
writer->writeFinal( 0.0 ); |
957 |
|
|
958 |
+ |
std::cout << "\n" |
959 |
+ |
<< "----------------------------------------\n" |
960 |
+ |
<< "\n" |
961 |
+ |
<< " final nLipids = " << nLipids << "\n" |
962 |
+ |
<< " final nWaters = " << nWaters << "\n" |
963 |
+ |
<< "\n"; |
964 |
+ |
|
965 |
|
return 1; |
966 |
|
} |
967 |
|
|