コード例 #1
0
ファイル: titrate.cpp プロジェクト: jmhenriques/faunus
int main() {
  cout << textio::splash();            // faunus splash info!
  ::atom.includefile("titrate.json");  // load atom properties
  InputMap mcp("titrate.input");
  EnergyDrift sys;                     // track system energy drift
  UnitTest test(mcp);

  // Space and hamiltonian
  Tspace spc(mcp);
  auto pot = Energy::Nonbonded<Tspace,Potential::DebyeHuckel>(mcp)
    + Energy::EquilibriumEnergy<Tspace>(mcp);

  // Add molecule to middle of simulation container
  string file = mcp.get<string>("molecule", string());
  Tspace::ParticleVector v;
  FormatAAM::load(file,v);
  Geometry::cm2origo(spc.geo,v); // center molecule
  Group g = spc.insert(v);       // insert into space
  g.name="peptide"; // babtise
  spc.enroll(g);    // enroll group in space

  spc.load("state");

  Move::SwapMove<Tspace> tit(mcp,pot,spc,pot.second);
  Analysis::ChargeMultipole mp;

  sys.init( Energy::systemEnergy(spc,pot,spc.p) );

  cout << atom.info() + spc.info() + pot.info() + tit.info()
    + textio::header("MC Simulation Begins!");

  MCLoop loop(mcp);            // class for handling mc loops
  while ( loop[0] ) {  // Markov chain 
    while ( loop[1] ) {
      sys+=tit.move();
      mp.sample(g,spc);
    } // end of micro loop

    sys.checkDrift( Energy::systemEnergy(spc,pot,spc.p) );
    cout << loop.timing();

  } // end of macro loop

  cout << loop.info() + sys.info() + tit.info() + g.info() + mp.info();

  FormatPQR().save("confout.pqr", spc.p);
  spc.save("state");
}
コード例 #2
0
ファイル: cyl.cpp プロジェクト: jmhenriques/faunus
int main(int argc, char** argv) {
    InputMap mcp("cyl.input");
    MCLoop loop(mcp);                    // class for handling mc loops
    FormatXTC xtc(1000);                 // XTC gromacs trajectory format
    EnergyDrift sys;                     // class for tracking system energy drifts
    UnitTest test(mcp);

    bool movie = mcp.get("movie", true);

    Tspace spc(mcp);
    auto pot = Energy::Nonbonded<Tspace,Tpairpot>(mcp)
               + Energy::ExternalPressure<Tspace>(mcp)
               + Energy::HydrophobicSASA<Tspace>(mcp)
               + Energy::EquilibriumEnergy<Tspace>(mcp);

    auto eqenergy = &pot.second;

    // set hydrophobic-hydrophobic LJ epsilon
    double epsh = mcp.get("eps_hydrophobic", 0.05);
    for (size_t i=0; i<atom.size()-1; i++)
        for (size_t j=i+1; j<atom.size(); j++)
            if (atom[i].hydrophobic)
                if (atom[j].hydrophobic)
                    pot.first.first.first.pairpot.second.customEpsilon(i,j,epsh);

    // Add molecules
    int N1 = mcp.get("molecule1_N",0);
    int N2 = mcp.get("molecule2_N",0);
    bool inPlane = mcp.get("molecule_plane", false);
    string file;
    vector<Group> pol(N1+N2);
    for (int i=0; i<N1+N2; i++) {
        if (i>=N1)
            file = mcp.get<string>("molecule2");
        else
            file = mcp.get<string>("molecule1");
        Tspace::ParticleVector v;

        // PQR or AAM molecular file format?
        if (file.find(".pqr")!=std::string::npos)
            FormatPQR::load(file,v);
        else
            FormatAAM::load(file,v);

        Geometry::FindSpace fs;
        if (inPlane)
            fs.dir=Point(0,0,1);
        fs.find(spc.geo,spc.p,v);
        pol[i] = spc.insert(v);
        pol[i].name=file+std::to_string(i);
        spc.enroll( pol[i] );
    }
    Group allpol( pol.front().front(), pol.back().back() );

    // Add atomic species
    Group salt;
    salt.addParticles(spc, mcp);
    salt.name="Atomic Species";
    spc.enroll(salt);

    Analysis::LineDistribution<> rdf(0.5);
    Analysis::ChargeMultipole mpol;
    Analysis::MultipoleDistribution<Tspace> mpoldist(mcp);
    FormatQtraj qtrj("qtrj.dat");

    spc.load("state");

    Move::Isobaric<Tspace> iso(mcp,pot,spc);
    Move::TranslateRotate<Tspace> gmv(mcp,pot,spc);
    Move::AtomicTranslation<Tspace> mv(mcp, pot, spc);
    Move::SwapMove<Tspace> tit(mcp,pot,spc,*eqenergy);
    if (inPlane)
        for (auto &m : pol)
            gmv.directions[ m.name ]=Point(0,0,1);

    eqenergy->eq.findSites(spc.p);

    sys.init( Energy::systemEnergy(spc,pot,spc.p) );    // Store total system energy

    cout << atom.info() << spc.info() << pot.info() << tit.info()
         << textio::header("MC Simulation Begins!");

    while ( loop.macroCnt() ) {  // Markov chain
        while ( loop.microCnt() ) {
            int k,i=rand() % 2;
            switch (i) {
            case 0:
                k=pol.size();
                while (k-->0) {
                    gmv.setGroup( pol[ rand() % pol.size() ] );
                    sys+=gmv.move();
                }
                for (auto i=pol.begin(); i!=pol.end()-1; i++)
                    for (auto j=i+1; j!=pol.end(); j++)
                        rdf( spc.geo.dist(i->cm,j->cm) )++;
                break;
            case 1:
                sys+=tit.move();
                break;
            case 2:
                sys+=iso.move();
                break;
            case 3:
                mv.setGroup(salt);
                sys+=mv.move();
                break;
            }

            double xi = slp_global(); // random number [0,1)

            // Sample multipolar moments and distribution
            if ( xi>0.95 ) {
                pol[0].setMassCenter(spc);
                pol[1].setMassCenter(spc);
                mpol.sample(pol,spc);
                mpoldist.sample(spc, pol[0], pol[1]);
            }

            if ( movie==true && xi>0.995 ) {
                xtc.setbox( 1000. );
                xtc.save("traj.xtc", spc.p);
                qtrj.save(spc.p);
            }
        } // end of micro loop

        sys.checkDrift( Energy::systemEnergy(spc,pot,spc.p) ); // detect energy drift
        cout << loop.timing();

        spc.save("state");
        mcp.save("mdout.mdp");
        rdf.save("rdf_p2p.dat");
        mpoldist.save("multipole.dat");
        FormatPQR::save("confout.pqr", spc.p);

    } // end of macro loop

    cout << loop.info() + sys.info() + gmv.info() + mv.info()
         + iso.info() + tit.info() + mpol.info();

}
コード例 #3
0
int main(int argc, char** argv) {
  Faunus::MPI::MPIController mpi;
  mpi.cout << textio::splash();

  InputMap mcp(textio::prefix+"manybody.input");
  MCLoop loop(mcp);                    // class for handling mc loops
  FormatPQR pqr;                       // PQR structure file I/O
  FormatAAM aam;                       // AAM structure file I/O
  FormatTopology top;
  FormatXTC xtc(1000);                 // XTC gromacs trajectory format for only cuboid geomtries
  EnergyDrift sys;                     // class for tracking system energy drifts
  UnitTest test(mcp);

  Energy::Hamiltonian pot;
  auto nonbonded = pot.create( Energy::Nonbonded<Tpairpot,Tgeometry>(mcp) );
  auto bonded    = pot.create( Energy::Bonded() );
//  auto mfc       = pot.create( Energy::MeanFieldCorrection(mcp) );  //pot.create returns a smart pointer!!
  auto swpair    = pot.create( Energy::PairListID() );
  swpair->add( atom["HIS"].id, atom["Zn"].id, Potential::SquareWell(mcp) );  //add square-well poteintial between Zn+2 and HIS resiues
  swpair->add( atom["ZNHIS"].id, atom["HIS"].id, Potential::SquareWellShifted(mcp, "squarewell_ZNHIS") );  //add square-well poteintial between ZNHIS and HIS resiues
#ifdef SLIT
  auto gouy = pot.create( Energy::GouyChapman(mcp) );
  gouy->setPosition( nonbonded->geometry.len_half.z() ); // Place the surface xy plane at +z direction
  auto restricted = pot.create( Energy::RestrictedVolumeCM(mcp) );
#endif
  Space spc( pot.getGeometry() );

  // Add polymers
  vector<GroupMolecular> pol( mcp.get("polymer_N",0) );
  string polyfile = mcp.get<string>("polymer_file", "");
  atom["MM"].dp = 0.;
  int ii=1;
  mpi.cout << "Number of polymers: " << pol.size() << endl;
  for (auto &g : pol) {                              // load polymers
    aam.load(polyfile);
    Geometry::FindSpace f;
    f.find(*spc.geo, spc.p, aam.particles());        // find empty spot in particle vector
    g = spc.insert( aam.particles() );               // insert into space
    ostringstream o;
    o << "Polymer" << ii++;
    g.name=o.str();
    spc.enroll(g);
#ifdef SLIT
    //(*restricted).groups.push_back( &g );   // Restrict center of masses of all proteins
    restricted->groups.push_back( &g );       // Restrict center of masses of all proteins
#endif
    for (int i=g.front(); i<g.back(); i++)
      bonded->add(i, i+1, Tbondpot(mcp, "polymer_", "minuslj_")); // add bonds
  }
  Group allpol( pol.front().front(), pol.back().back() ); // make group w. all polymers
  
  // Add salts
  GroupAtomic salt(spc, mcp);
  salt.name="salt";
  mpi.cout << "Number of salts: " << salt.size() << endl;

  // atom["NTR"].dp = 10.;
  // atom["CTR"].dp = 10.;
  // atom["HIS"].dp = 10.;
  // atom["HNTR"].dp = 10.;
  // atom["HCTR"].dp = 10.;
  // atom["HHIS"].dp = 10.;

  //Move::Isobaric iso(mcp,pot,spc);
  Move::TranslateRotate gmv(mcp,pot,spc);
  Move::AtomicTranslation mv(mcp, pot, spc);
  Move::AtomicTranslation mv2(mcp, pot, spc, "ion");
  Move::SwapMove tit(mcp,pot,spc);
  Move::CrankShaft crank(mcp, pot, spc);
  Move::Pivot pivot(mcp, pot, spc);
  Move::ParallelTempering temper(mcp,pot,spc,mpi);
  Move::Reptation rep(mcp, pot, spc);

  Analysis::RadialDistribution<float,int> rdf(0.25);
#ifdef SLIT
  Analysis::LineDistribution<float,int> surfdist(0.25), surfmapall(0.25);
  //std::map< string , Analysis::LineDistribution<float,int> > surfmap, surfmapall;
  std::map< int , Analysis::LineDistribution<float,int> > surfmap_res;
  typedef Analysis::Table2D<double, Average<double> > Ttable;
  std::map<string , Ttable> dst_map;
#endif
  Analysis::ChargeMultipole mpol;
  Analysis::PolymerShape shape;
  spc.load(textio::prefix+"state");

  sys.init( Energy::systemEnergy(spc,pot,spc.p) );

  mpi.cout << atom.info() << spc.info() << pot.info() << tit.info()
    << textio::header("MC Simulation Begins!");

  while ( loop.macroCnt() ) {  // Markov chain 
    while ( loop.microCnt() ) {
      int k,i=rand() % 6;
      switch (i) {
        case 0: // translate and rotate molecules
          k=pol.size()+salt.size();
          while (k-->0) {
            int s=rand()%2;
            if (s==1) {
              gmv.setGroup( pol.at( rand() % pol.size() ) );
              sys+=gmv.move(); 
            }
            else {
              mv2.setGroup(salt); // translate salt particles 
              if (salt.size()>0)
                sys+=mv2.move( rand() % salt.size() ); 
            }
          }
#ifdef SLIT
          for (auto &g : pol) {
            //surfmap[g.name]( gouy->dist2surf(g.cm) )++;
            surfdist( gouy->dist2surf(g.cm) )++; // polymer mass center to GC surface histogram
	    for (int i=g.front(); i<=g.back(); i++) {
              surfmap_res[i]( gouy->dist2surf( spc.p[i] ) )++; // monomer to GC surface histogram
              surfmapall( gouy->dist2surf( spc.p.at(i) ) )++;
            }
          }
#endif
          for (auto i=pol.begin(); i!=pol.end()-1; i++)
            for (auto j=i+1; j!=pol.end(); j++)
              rdf( spc.geo->dist(i->cm,j->cm) )++; // sample polymer-polymer rdf
          break;
        case 1:
          mv.setGroup(allpol);
          sys+=mv.move( allpol.size() ); // translate monomers
          for (auto &g : pol) {
            g.setMassCenter(spc);
            shape.sample(g,spc);
          }
          break;
        case 2: // titration move
          sys+=tit.move();
          mpol.sample(pol,spc);
          break;
        case 3: // crankshaft move
          k=pol.size();
          while (k-->0) {
            crank.setGroup( pol[ rand() % pol.size() ] );
            sys+=crank.move();
          }
          for (auto &g : pol) {
            g.setMassCenter(spc);
            shape.sample(g,spc);
          }
          break;
        case 4: // pivot move
          k=pol.size();
          while (k-->0) {
            pivot.setGroup( pol[ rand() % pol.size() ] );
            sys+=pivot.move();
          }
          for (auto &g : pol) {
            g.setMassCenter(spc);
            shape.sample(g,spc);
          }
          break;
        case 5: // reptation move
          k=pol.size();
          while (k-->0) {
            rep.setGroup( pol[ rand() % pol.size() ] );
            sys+=rep.move();
          }
          for (auto &g : pol) {
            g.setMassCenter(spc);
            shape.sample(g,spc);
          }
          break;
        //case 5: // volume move
          //sys+=iso.move();
         // break;
        }

      if ( slp_global.runtest(0.00001) ) {
        xtc.setbox( nonbonded->geometry.len );
        xtc.save(textio::prefix+"traj.xtc", spc);
      }
      //if ( slp_global.runtest(0.1) ) 
        //(*mfc).sample(spc.p, )
#ifdef SLIT
      if ( slp_global.runtest(0.1) ) {
         for (auto &g : pol) {
           double d = gouy->dist2surf(g.cm);
           dst_map["Q"]( d )+=g.charge(spc.p);
           Point p=shape.vectorgyrationRadiusSquared(g, spc);
           dst_map["Rg2"]( d )+=p.x()+p.y()+p.z();
           dst_map["Rg2x"]( d )+=p.x();
           dst_map["Rg2z"]( d )+=p.z();
           dst_map["Ree2"]( d )+=spc.geo->sqdist( spc.p[g.front()], spc.p[g.back()] );
           //dst_map["<Energy>"]( d )+=sys.current();
           for (int i=g.front(); i<=g.back(); i++){
            ostringstream o;
            o << "qres" << i ;
            dst_map[o.str()]( d )+=spc.p[i].charge;
           }
         } 
      }
#endif

    } // end of micro loop

    temper.setCurrentEnergy( sys.current() );
    sys+=temper.move();

    sys.checkDrift( Energy::systemEnergy(spc,pot,spc.p) );

    mpi.cout << loop.timing();
    cout << loop.timing();

    rdf.save(textio::prefix+"rdf_p2p.dat");

#ifdef SLIT
    surfdist.save(textio::prefix+"surfdist.dat");
    surfmapall.save(textio::prefix+"surfall.dat");
    dst_map["Q"].save(textio::prefix+"netq.dat");
    //dst_map["<Energy>"].save(textio::prefix+"aveenergy.dat");

    for (auto &g : pol){   //Saving averages 
      //surfmap[g.name].save(textio::prefix+g.name+"surfdist.dat");
      std::ofstream f(textio::prefix+"res-surfdist.dat");
      std::ofstream f1(textio::prefix+"Rg-comp.dat");
      std::ofstream f2(textio::prefix+"qres.dat");
      f.precision(7);
      f1.precision(7);
      f2.precision(7);
      if (f && f1 && f2) {
        //f << "#g(z) of each residue from 1 to " << g.size() << endl;
        for (double d=0; d<=nonbonded->geometry.len.z(); d+=0.25){
          f1 << d; 
          if (dst_map["Rg2"](d).cnt > 0) f1 << "\t" << dst_map["Rg2"](d); //If counter is empty, then it prints shit lot of warning
          else f1 << "\t0";

          if (dst_map["Rg2x"](d).cnt > 0)f1 << "\t" << dst_map["Rg2x"](d); 
          else f1 << "\t0";

          if (dst_map["Rg2z"](d).cnt > 0)  f1 << "\t" << dst_map["Rg2z"](d); 
          else f1 << "\t0";

          if (dst_map["Ree2"](d).cnt > 0)  f1 << "\t" << dst_map["Ree2"](d); 
          else f1 << "\t0";
          f1 << endl;

          f << d; 
          f2 << d;
          for (int i=g.front(); i<=g.back(); i++){
            f << "\t" << surfmap_res[i](d);
            ostringstream o;
            o << "qres" << i ;
            if (dst_map[o.str()]( d ).cnt > 0 ) f2 << "\t" << dst_map[o.str()]( d );
            else f2 << "\t0"; 
          }
          f << endl;
          f2 << endl;
        }
      }
    }
#endif

    pqr.save(textio::prefix+"confout.pqr", spc.p);
    aam.save(textio::prefix+"confout.aam", spc.p);
    mcp.save(textio::prefix+"mdout.mdp");
    spc.save(textio::prefix+"state");


  } // end of macro loop

  mpi.cout << loop.info() << sys.info() << gmv.info() <<  mv.info() << mv2.info() 
    << crank.info() << pivot.info() << rep.info() << temper.info() 
    << tit.info() << mpol.info()  <<  shape.info() << spc.info();   

  tit.applycharges(spc.p);
  pqr.save(textio::prefix+"conf_aveq.pqr", spc.p);
  aam.save(textio::prefix+"conf_aveq.aam", spc.p);

}
コード例 #4
0
ファイル: cyl.cpp プロジェクト: carolinacragnell/faunus
int main(int argc, char** argv) {
  InputMap mcp("cyl.input");
  MCLoop loop(mcp);                    // class for handling mc loops
  FormatXTC xtc(1000);                 // XTC gromacs trajectory format
  EnergyDrift sys;                     // class for tracking system energy drifts
  UnitTest test(mcp);
  bool inPlane = mcp.get<bool>("molecule_plane");

  Tspace spc(mcp);
  auto pot = Energy::Nonbonded<Tspace,Tpairpot>(mcp)
    + Energy::MassCenterConstrain<Tspace>(mcp) 
    + Energy::EquilibriumEnergy<Tspace>(mcp);

  auto constrainenergy = &pot.first.second;
  auto eqenergy = &pot.second;

  // Add molecules
  int N1 = mcp.get("molecule1_N",0);
  int N2 = mcp.get("molecule2_N",0);
  string file;
  vector<Group> pol(N1+N2);
  for (int i=0; i<N1+N2; i++) {
    if (i>=N1)
      file = mcp.get<string>("molecule2");
    else
      file = mcp.get<string>("molecule1");
    Tspace::ParticleVector v;
    FormatAAM::load(file,v);
    Geometry::FindSpace fs;
    if (inPlane)
      fs.dir=Point(0,0,1);
    fs.find(spc.geo,spc.p,v);
    pol[i] = spc.insert(v);
    pol[i].name=file+std::to_string(i);
    spc.enroll( pol[i] );
  }
  Group allpol( pol.front().front(), pol.back().back() );

  constrainenergy->addPair(pol[0], pol[1]);

  // Add atomic species
  Group salt;
  salt.addParticles(spc, mcp);
  salt.name="Atomic Species";
  spc.enroll(salt);

  Analysis::LineDistribution<> rdf(0.5);
  Analysis::ChargeMultipole mpol;

  spc.load("state");

  Move::Isobaric<Tspace> iso(mcp,pot,spc);
  Move::TranslateRotate<Tspace> gmv(mcp,pot,spc);
  Move::AtomicTranslation<Tspace> mv(mcp, pot, spc);
  Move::SwapMove<Tspace> tit(mcp,pot,spc,*eqenergy);
  if (inPlane)
    for (auto &m : pol)
      gmv.directions[ m.name ]=Point(0,0,1);

  eqenergy->eq.findSites(spc.p);

  sys.init( Energy::systemEnergy(spc,pot,spc.p) );    // Store total system energy

  cout << atom.info() << spc.info() << pot.info() << tit.info()
    << textio::header("MC Simulation Begins!");

  while ( loop.macroCnt() ) {  // Markov chain 
    while ( loop.microCnt() ) {
      int k,i=rand() % 2;
      switch (i) {
        case 0:
          k=pol.size();
          while (k-->0) {
            gmv.setGroup( pol[ rand() % pol.size() ] );
            sys+=gmv.move();
          }
          for (auto i=pol.begin(); i!=pol.end()-1; i++)
            for (auto j=i+1; j!=pol.end(); j++)
              rdf( spc.geo.dist(i->cm,j->cm) )++;
          break;
        case 1:
          sys+=tit.move();
          if( slp_global()>0.9 )
            mpol.sample(pol,spc);
          break;
        case 2:
          sys+=iso.move();
          break;
        case 3:
          mv.setGroup(salt);
          sys+=mv.move();
          break;
      }
      if ( slp_global()<-0.001 ) {
        xtc.setbox( 1000. );
        xtc.save("traj.xtc", spc);
      }
    } // end of micro loop

    sys.checkDrift( Energy::systemEnergy(spc,pot,spc.p) ); // detect energy drift
    cout << loop.timing();

    rdf.save("rdf_p2p_macro" + std::to_string(loop.getMacroCnt()) +".dat");
    FormatPQR::save("confout.pqr", spc.p);
    spc.save("state");
    mcp.save("mdout.mdp");

  } // end of macro loop

  cout << loop.info() + sys.info() + gmv.info() + mv.info()
    + iso.info() + tit.info() + mpol.info();
}