18 #define MIN_DEBUG_LEVEL 1    30     BigReal itmp3 = 1.0f / (point[0]*mat[3] + point[1]*mat[7] +
    31                             point[2]*mat[11] + mat[15]);
    32     tmp[0] = itmp3*point[0];
    33     tmp[1] = itmp3*point[1];
    34     tmp[2] = itmp3*point[2];
    35     point[0]=tmp[0]*mat[0] + tmp[1]*mat[4] + tmp[2]*mat[ 8] + itmp3*mat[12];
    36     point[1]=tmp[0]*mat[1] + tmp[1]*mat[5] + tmp[2]*mat[ 9] + itmp3*mat[13];
    37     point[2]=tmp[0]*mat[2] + tmp[1]*mat[6] + tmp[2]*mat[10] + itmp3*mat[14];
    41     memset(mat, 0, 16*
sizeof(
BigReal));
    52         tmp[4*i+j] = mat[i+4*j];
    55     for(i=0;i<16;i++) mat[i] = tmp[i];
    60     for (
int j=0; j<4; j++) {
    65       for (
int i=0; i<4; i++) {
    66         mat[4*i+j] = m.mat[4*i]*tmp[0] + m.mat[4*i+1]*tmp[1] +
    67           m.mat[4*i+2]*tmp[2] + m.mat[4*i+3]*tmp[3]; 
    82   DebugM(3,
"initialize called\n");
   105   map <int, vector<int> >::iterator it;
   106   for (it = dmap.begin(); it != dmap.end(); ++it){  
   109     for(
int i = 0; i<it->second.size(); i++){
   110       char aloc = altloc[it->second[i]];
   111       if ( aloc & 1 ) ++biascount;
   112       if ( aloc & 2 ) ++refcount;
   114     altlocmap[it->first] = ( refcount ? 1 : 0 );
   115     if ( ! refcount ) refcount = it->second.size();
   116     iout << 
iINFO << 
"TMD domain " << it->first <<
   117       " has " << it->second.size() << 
" atoms " <<
   118       refcount << 
" fitted " << biascount << 
" biased\n" << 
endi;
   123   DebugM(1,
"done with initialize\n");
   126 void GlobalMasterTMD::parseAtoms(
const char *file, 
int numTotalAtoms, 
bool isTwo) {
   127   DebugM(3,
"parseAtoms called\n");
   131     NAMD_die(
"No atoms found in TMDFile\n");
   133     iout << 
iWARN << 
"The number of atoms in TMDFile is less than the total number of atoms in the structure.\n" << 
endi;
   135     NAMD_die(
"The number of atoms in TMDFile must not exceed the total number of atoms in the structure!");
   136   if ( modifyRequestedAtoms().size() )
   137     NAMD_bug(
"GlobalMasterTMD::parseAtoms() modifyRequestedAtoms() not empty");
   143     tmdpdb.get_all_positions(atompos2);
   149     tmdpdb.get_all_positions(atompos);
   151   if ( ! altloc ) altloc = 
new char[
numatoms];
   154 #ifdef MEM_OPT_VERSION   155     PDBCoreData *atom = tmdpdb.atom(i);
   156     char aloc = tmdpdb.alternatelocation(i);
   158     PDBAtom *atom = tmdpdb.atom(i); 
   161     if ( aloc ) aloc -= 
'0';
   162     if ( aloc ) aloc = 2;  
   167         target2[3*numTMDatoms  ] = atompos2[i].x;
   168         target2[3*numTMDatoms+1] = atompos2[i].y;
   169         target2[3*numTMDatoms+2] = atompos2[i].z;
   172         target[3*numTMDatoms  ] = atompos[i].x;
   173         target[3*numTMDatoms+1] = atompos[i].y;
   174         target[3*numTMDatoms+2] = atompos[i].z;
   178         modifyRequestedAtoms().add(i);
   181         map <int, vector<int> >::iterator it = dmap.find((
int)atom->
temperaturefactor());
   182         if (it != dmap.end()){
   183           it->second.push_back(i); 
   192   DebugM(1,
"done with parseAtoms\n");
   196 void GlobalMasterTMD::NewTarget(
int domain)
   198   map <int, vector<int> >::iterator it = dmap.find(domain);
   201   target = 
new BigReal [3*it->second.size()];
   202   for(
int i = 0; i<it->second.size(); i++){
   203    target[3*i  ] = atompos[it->second[i]].x;
   204    target[3*i+1] = atompos[it->second[i]].y;
   205    target[3*i+2] = atompos[it->second[i]].z; 
   209    target2 = 
new BigReal [3*it->second.size()];
   210    for(
int i = 0; i<it->second.size(); i++){
   211      target2[3*i  ] = atompos2[it->second[i]].x;
   212      target2[3*i+1] = atompos2[it->second[i]].y;
   213      target2[3*i+2] = atompos2[it->second[i]].z; 
   216   delete [] weight;  weight = 0;
   217   if ( altlocmap.find(domain)->second ) {
   218     weight = 
new BigReal [it->second.size()];
   219     for(
int i = 0; i<it->second.size(); i++){
   220       weight[i] = ( (altloc[it->second[i]] & 2) ? 1.0 : 0.0 );
   236 void GlobalMasterTMD::calculate() {
   238   modifyAppliedForces().resize(0);
   239   modifyForcedAtoms().resize(0);
   242   if (currentStep < firstStep || currentStep >= lastStep) {
   247   map<int, Position> positions;
   254   for ( ; a_i != a_e; ++a_i, ++p_i ){
   255     positions[*a_i] = *p_i;
   259   map <int, vector<int> >::iterator it;
   260   for (it = dmap.begin(); it != dmap.end(); ++it){  
   261   NewTarget(it->first);  
   264   for (
int i = 0; i < it->second.size(); i++){
   266     curpos[3*i  ] = positions[it->second[i]].x;
   267     curpos[3*i+1] = positions[it->second[i]].y;
   268     curpos[3*i+2] = positions[it->second[i]].z;
   272   curpos2 = 
new BigReal[3*(it->second.size())];
   273   for (
int i = 0; i < it->second.size(); i++){
   275     curpos2[3*i  ] = positions[it->second[i]].x;
   276     curpos2[3*i+1] = positions[it->second[i]].y;
   277     curpos2[3*i+2] = positions[it->second[i]].z;
   282   BigReal ttt[16], pre[3], post[3];
   285   if (initialRMS < 0) {
   293     curRMS1 = 
MatrixFitRMS(it->second.size(), target2, curpos2, weight, ttt1);
   294     curRMS = curRMS0 - curRMS1 ;
   299                             (lastStep-firstStep);
   301   BigReal targetRMS = initialRMS * (1-frac) + frac * finalRMS;
   307   if (((finalRMS <= initialRMS && targetRMS <= curRMS) ||
   308       (finalRMS >= initialRMS && targetRMS >= curRMS) ||
   309       qDiffRMSD) && (curRMS0 > 0. && curRMS1 > 0) ) {
   316     for (j=0; j<3; j++) {
   317       post[j] = ttt[4*j+3];
   329       for (
int i=0; i<it->second.size(); i++) {
   332         k = kmap[it->second[i]];  
   333       } 
else if ( (! weight) || (altloc[it->second[i]] & 1) ) {
   334         k = K/it->second.size();  
   337       BigReal prefac = k * (targetRMS - curRMS)/curRMS0;
   339       BigReal dx = curpos[3*i  ] - target[3*i  ];
   340       BigReal dy = curpos[3*i+1] - target[3*i+1];
   341       BigReal dz = curpos[3*i+2] - target[3*i+2];
   343       BigReal fvec[3] = { dx, dy, dz };
   344       Vector force(fvec[0]*prefac, fvec[1]*prefac, fvec[2]*prefac);
   345       modifyForcedAtoms().add(it->second[i]);
   346       modifyAppliedForces().add(force);
   347       BigReal force2 = force.length2();
   348       if ( force2 > maxforce2 ) maxforce2 = force2;
   353       for (j=0; j<3; j++) {
   354         post[j] = ttt1[4*j+3];
   367         for (
int i=0; i<it->second.size(); i++) {
   370           k = kmap[it->second[i]];  
   371         } 
else if ( (! weight) || (altloc[it->second[i]] & 1) ) {
   372           k = K/it->second.size();  
   376           BigReal prefac1 = - k * (targetRMS  - curRMS)/curRMS1; 
   379         BigReal dx = curpos2[3*i  ] - target2[3*i  ];
   380         BigReal dy = curpos2[3*i+1] - target2[3*i+1];
   381         BigReal dz = curpos2[3*i+2] - target2[3*i+2];
   382         BigReal fvec[3] = { dx, dy, dz };
   383         Vector force(fvec[0]*prefac1, fvec[1]*prefac1, fvec[2]*prefac1);
   384         modifyForcedAtoms().add(it->second[i]);
   385         modifyAppliedForces().add(force);
   386         BigReal force2 = force.length2();
   387         if ( force2 > maxforce2 ) maxforce2 = force2;
   393   if(qDiffRMSD){
delete [] curpos2;}
   395   if (currentStep % outputFreq == 0) {
   396     iout << 
"TMD  " << currentStep << 
" Domain: "<< it->first << 
" " << targetRMS << 
' ' << curRMS << 
'\n' << 
endi; 
 
void multmatrix(const Matrix4TMD &m)
premultiply the matrix by the given matrix, this->other * this 
std::ostream & iINFO(std::ostream &s)
BigReal temperaturefactor(void)
SimParameters * simParameters
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
Matrix4TMD(const BigReal *m)
const AtomID * const_iterator
void NAMD_bug(const char *err_msg)
char TMDFile[NAMD_FILENAME_BUFFER_SIZE]
void translate(BigReal x, BigReal y, BigReal z)
const char * alternatelocation(void)
void NAMD_die(const char *err_msg)
void multpoint(BigReal point[3]) const
BigReal MatrixFitRMS(int n, BigReal *v1, BigReal *v2, const BigReal *wt, BigReal *ttt)
char TMDFile2[NAMD_FILENAME_BUFFER_SIZE]
void translate(BigReal d[3])