void Molecule::print_torsion_angles()
{
  printf("\nTorsion/Dihedral angles [degrees]:\n");
  for (int i = 0; i < natom; i++)
    for (int j = 0; j < i; j++)
      for (int k = 0; k < j; k++)
	for (int l = 0; l < k; l++)
	  if (bond(i,j) < 4.0 && bond(j,k) < 4.0 && bond(k,l) < 4.0)
	    printf("%3d %3d %3d %3d %10.6f\n", i, j, k, l, angle_torsion(i,j,k,l));
}
void Molecule::print_oop_angles()
{
  printf("\nOut-of-plane angles [degrees]:\n");
  for (int i = 0; i < natom; i++)
    for (int k = 0; k < natom; k++)
      for (int j = 0; j < natom; j++)
	for (int l = 0; l < j; l++)
	  if (i!=j && i!=k && i!=l && j!=k && k!=l && bond(i,k) < 4.0 && bond(k,j) < 4.0 && bond(k,l) < 4.0)
	    printf("%3d %3d %3d %3d %10.6f\n", i, j, k, l, angle_oop(i,j,k,l));
}
Exemple #3
0
void* hydroFn(void* arg){
    while(1){
        sem_wait(&smutex);

        hydregen+=1;

        if(hydregen>=2 && oxygen>=1){
            sem_post(&hydroQueue);
            sem_post(&hydroQueue);
            hydregen-=2;
            sem_post(&oxyQueue);
            oxygen-=1;
        }
        else{
            sem_post(&smutex);
        }

        sem_wait(&hydroQueue);

        printf("Hydrogen Bond\n");
        bond();

        barrier_wait();
        }

}
void Molecule::print_bonds()
{
  printf("\nInteratomic distances [bohr]:\n");
  for (int i = 0; i < natom; i++)
    for (int j = 0; j < i; j++)
      printf("%3d %3d %10.6f\n", i, j, bond(i,j));
}
/** checks leftVertex<->conjBond consistency, bond sorting in vertices, and bond sorting in cells */
bool TissueState::checkTopologicalConsistency() const {
  const double Small = 1e-8;
  
  // leftVertex<->conjBond consistency and comparison of bond lengths
  for(TissueState::BondIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
    DirectedBond *b = bond(it);
    if(b->conjBond && (b->leftVertex!=b->conjBond->rightVertex)) {
      std::cout << "TissueState::checkTopologicalConsistency: inconsistency in bond between leftVertex = " << b->leftVertex << " and conjBond->rightVertex: " << b->conjBond->rightVertex << std::endl;
      std::cout << "TissueState::checkTopologicalConsistency: vertices " << b->rightVertex->r.x() << ", " << b->rightVertex->r.y() << " and " << b->conjBond->rightVertex->r.x() << ", " << b->conjBond->rightVertex->r.y() << std::endl;
      return false;
    }
    if(b->conjBond && (fabs(b->length-b->conjBond->length)>Small)) {
      std::cout << "TissueState::checkTopologicalConsistency: inconsistency in bond length " << b->rightVertex->r << "->" << b->leftVertex->r << "; diff: " << b->length-b->conjBond->length << std::endl;
    }
  }
  
  // vertex sorting
  for(unsigned int i=0; i<_vertices.size(); ++i) {
    Vertex *v = _vertices[i];
    if(v->bonds.size()>0) {
      Cell *lastCell = v->bonds[v->bonds.size()-1]->cell;
  //    std::cout << "TissueState::checkTopologicalConsistency: vertex " << v->r.x() << ", " << 1946-v->r.y() << ", size: " << v->bonds.size() << std::endl;
  //    std::cout << "TissueState::checkTopologicalConsistency: vertices " << v->bonds[v->bonds.size()-1]->rightVertex->r.x() << ", " << 1946-v->bonds[v->bonds.size()-1]->rightVertex->r.y() << " and " << v->bonds[v->bonds.size()-1]->leftVertex->r.x() << ", " << 1946-v->bonds[v->bonds.size()-1]->leftVertex->r.y() << std::endl;
      for(unsigned int j=0; j<v->bonds.size(); ++j) {
        DirectedBond *b = v->bonds[j];
  //      std::cout << "TissueState::checkTopologicalConsistency: vertices " << b->rightVertex->r.x() << ", " << 1946-b->rightVertex->r.y() << " and " << b->leftVertex->r.x() << ", " << 1946-b->leftVertex->r.y() << std::endl;
        if(b->conjBond && (lastCell!=b->conjBond->cell)) {
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, vertex: " << v << std::endl;
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, conjBond: " << b->conjBond << std::endl;
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, conjBondCell: " << std::hex << b->conjBond->cell->id << std::endl;
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, lastCell: " << lastCell->id << std::endl;
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, bond: " << b << std::endl;
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in vertex sorting, cell: " << b->cell->id << std::endl;
  //        std::cout << "TissueState::checkTopologicalConsistency: cells " << std::hex << lastCell->id << ", " << b->conjBond->cell->id << "; " << b->cell->id << "." << std::endl;
  //         std::cout << "TissueState::checkTopologicalConsistency: vertices " << b->rightVertex->r.x() << ", " << 1946-b->rightVertex->r.y() << " and " << b->conjBond->rightVertex->r.x() << ", " << 1946-b->conjBond->rightVertex->r.y() << std::endl;
          return false;
        }
        lastCell = b->cell;
      }
    }
  }
  
  // cell sorting
  for(CellConstIterator it=beginCellIterator(); it!=endCellIterator(); ++it) {
    Cell *c = cell(it);
    if(c->bonds.size()>0) {
      Vertex *lastVertex = c->bonds[c->bonds.size()-1]->leftVertex;
      for(unsigned int j=0; j<c->bonds.size(); ++j) {
        DirectedBond *b = c->bonds[j];
        if(lastVertex!=b->rightVertex) {
          std::cout << "TissueState::checkTopologicalConsistency: inconsistency in cell sorting!" << std::endl;
          return false;
        }
        lastVertex = b->leftVertex;
      }
    }
  }
  
  return true;
}
Exemple #6
0
RcppExport SEXP cfamounts(SEXP params){
       
    SEXP rl=R_NilValue;
    char* exceptionMesg=NULL;
    try{
        RcppParams rparam(params); 

        QuantLib::Date maturity(dateFromR(rparam.getDateValue("Maturity")));
        QuantLib::Date settle(dateFromR(rparam.getDateValue("Settle")));
        QuantLib::Date issue(dateFromR(rparam.getDateValue("IssueDate")));

        double rate = rparam.getDoubleValue("CouponRate");
        std::vector<double> rateVec(1, rate);
        double faceAmount = rparam.getDoubleValue("Face");
        double period = rparam.getDoubleValue("Period");
        double basis = rparam.getDoubleValue("Basis");
        DayCounter dayCounter = getDayCounter(basis);
        Frequency freq = getFrequency(period);
        Period p(freq);
        double EMR = rparam.getDoubleValue("EMR");
        Calendar calendar=UnitedStates(UnitedStates::GovernmentBond);
        
        
        Schedule sch(settle, maturity, p, calendar, 
                     Unadjusted, Unadjusted, DateGeneration::Backward, 
                     (EMR == 1)? true : false);

        FixedRateBond bond(1, faceAmount, sch, rateVec, dayCounter, Following,
                           100, issue);

        //cashflow
        int numCol = 2;
        std::vector<std::string> colNames(numCol);
        colNames[0] = "Date";
        colNames[1] = "Amount";
        RcppFrame frame(colNames);
        
        Leg bondCashFlow = bond.cashflows();
        for (unsigned int i = 0; i< bondCashFlow.size(); i++){
            std::vector<ColDatum> row(numCol);
            Date d = bondCashFlow[i]->date();
            row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year()));
            row[1].setDoubleValue(bondCashFlow[i]->amount());
            frame.addRow(row);
        }
                     
        RcppResultSet rs;
        rs.add("cashFlow", frame);
        rl = rs.getReturnList();

    } catch(std::exception& ex) {
        exceptionMesg = copyMessageToR(ex.what());
    } catch(...) {
        exceptionMesg = copyMessageToR("unknown reason");
    }   
    if(exceptionMesg != NULL)
        Rf_error(exceptionMesg);    
    return rl;
}
Exemple #7
0
//Proces prvku
int atom(unsigned ID,char prvok)
{
    //Vypis hlasky started
    //moze sa vypisat prakticky kedykolvek, preto je pred semaforom
    sem_wait(&premenne->sem);
    vypis("%u\t: %c %u\t:started\n",prvok,ID);
    sem_post(&premenne->sem);

    //Semafor aby sme nenarusili proces bondovania
    sem_wait(&semafory->Next_Create_Bond);
    //Ziskame si pristup do zdielanej pamate
    sem_wait(&premenne->sem);

    //Zapiseme si do zdielanej premennej ze mame proces vhodny na bondovanie, danej kategorie
    if ( prvok == 'H' )
        premenne->amount_H++;
    else
        premenne->amount_O++;

    //Zistenie ci sa da viazat
    if( premenne->amount_H >= 2 && premenne->amount_O >= 1 ) //Ak je dost atomov na viazanie
        {
            vypis("%u\t: %c %u\t:ready\n",prvok,ID);
            premenne->bonding=6;
            sem_post(&semafory->H_queue);
            //Podla toho ci bond spustil vodik alebo kyslik sa prebudzaju procesi s ktorimi sa budeme bondovat
            if ( prvok == 'O' )
                sem_post(&semafory->H_queue);
            else
                sem_post(&semafory->O_queue);
            premenne->amount_H-=2;
            premenne->amount_O--;
            sem_post(&premenne->sem); //Koniec kritickej sekcie ak je dost na viazanie
        }
        else
        {
            vypis("%u\t: %c %u\t:waiting\n",prvok,ID);
            sem_post(&premenne->sem); //Koniec kritickej sekcie ak nie je dost na viazanie
            sem_post(&semafory->Next_Create_Bond);
            if ( prvok == 'O' )
                sem_wait(&semafory->O_queue);
            else
                sem_wait(&semafory->H_queue);
        }

    //Proces bondovania
    bond(prvok,ID);

    //Vypis hlasky finished
    finished(prvok,ID);

    exit(EXIT_SUCCESS);
}
void force(){
	int i,j;
	epot = 0.0;
		
	repel();
	bond();
	bend3(1,tot_pol1);
	bend3(tot_pol1+1,tot_amino);
	end_tangent();
	pull(); // apply "pull_force" in z direction for bead "tot_pol1" 

}
Exemple #9
0
void BuildAtom::leftMouseReleaseEvent(QMouseEvent* e) 
{
   m_viewer->setMouseBinding(Qt::NoModifier, Qt::LeftButton, QGLViewer::CAMERA, 
      QGLViewer::ROTATE);
   if (!m_molecule) return;
   Q_UNUSED(e);

   if (m_bond == 0) {
      if (m_beginAtom != 0 ) {
         if (m_existingAtom == 0 || m_beginAtom == m_existingAtom) {
		    // Effectivly a left click on a single atom, change atom number to
            // current build element
            if (m_beginAtom->getAtomicNumber() != (int)m_buildElement) {
               Command::ChangeAtomType* cmd = new Command::ChangeAtomType(m_beginAtom);
               m_beginAtom->setAtomicNumber(m_buildElement);
               m_viewer->postCommand(cmd);
            }
            //m_viewer->updateLabels();
         }else if (m_existingAtom != 0 && m_endAtom == 0) {
		    // we have dragged from one existing atom to another, so we increase
            // the bond order.
            Layer::Bond* bond(m_molecule->getBond(m_beginAtom, m_existingAtom));
            if (bond) {
               Command::ChangeBondOrder* cmd = new Command::ChangeBondOrder(bond);
               bond->setOrder(bond->getOrder()+1);
               m_viewer->postCommand(cmd);
            }
         }
      }
   }

   Layer::PrimitiveList primitives;
   Layer::Primitive* primitive;
   for (int i = 0; i < m_buildObjects.size(); ++i) {
       primitive = qobject_cast<Layer::Primitive*>(m_buildObjects[i]);
       if (primitive) primitives.append(primitive);
   }

   // If the user clicks and releases after moving the cursor only slightly, it
   // is possible that two atoms have been created more or less on top of each
   // other.  This is not detected by the Viewer selection routine as the objects
   // in m_buildObjects do not participate in the selection.

   if (!primitives.isEmpty()) {
      QString msg("Add atoms/bonds");
      Command::EditPrimitives* cmd(new Command::EditPrimitives(msg, m_molecule));
      cmd->add(primitives);
      m_viewer->postCommand(cmd);
   }
}
void TissueState::cleanUp() {
  for(vector<Vertex*>::iterator it=_vertices.begin(); it!=_vertices.end(); ++it) {
    delete *it;
  }
  for(BondIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
    delete bond(it);
  }
  for(CellIterator it=beginCellIterator(); it!=endCellIterator(); ++it) {
    delete cell(it);    
  }
  _vertices.clear();
  _bonds.clear();
  _cells.clear();
}
Exemple #11
0
    // ==============================
    // compute_bonds
    // ==============================
    void compute_bonds(){
	/*
	 * effect:
	 *   bonds[i] stores the i-th bond, and bonds.size() is the number of bonds.
	 *   if boundary_condition_x is set to 'o', then bulk-bulk and bulk-boundary bonds are computed in the x direction but not boundary-boundary
	 *   if boundary_condition_x is set to 'p', then bulk-bulk, bulk-boundary and boundary-boundary bonds are computed in the x direction
	 *   here a boundary cell in the x direction is a cell(i,j,k) with i==0 or i==num_cells_x-1
	 *
	 * method:
	 *   The plan is to cycle through cells. For each cell cycle through particles in it.
	 *   For each of those particles, cycle through all particles in all neighboring cells.
	 *   Mark a particle that checked all adjacent particles as "used" so bonds won't be counted twice.
	 *   For open boundary conditions cycle through bulk cells (neighbor cells may belong to boundary).
	 *   For periodic boundary conditions cycle through all cells
	 */
		
		
	std::vector<int> used(num_particles); //sets all values to zero
	int i, i_i, i_f, ii; 
	int j, j_i, j_f, jj;
	int k, k_i, k_f, kk;
	int count=0;
	particle p1,p2;
	boundary_condition_x=='o' ? (i_i=1,i_f=num_cells_x-2) : (i_i=0,i_f=num_cells_x-1);
	boundary_condition_y=='o' ? (j_i=1,j_f=num_cells_y-2) : (j_i=0,j_f=num_cells_y-1);
	boundary_condition_z=='o' ? (k_i=1,k_f=num_cells_z-2) : (k_i=0,k_f=num_cells_z-1);

	for(i=i_i; i<=i_f; i++) for(j=j_i; j<=j_f; j++) for(k=k_i; k<=k_f; k++){
		    //boost::numeric::ublas::vector<particle>::iterator it(cell(i,j,k).begin()), itend(cell(i,j,k).end());
		    for(int num1=0; num1<cell(i,j,k).size(); num1++){
			p1=cell(i,j,k)[num1];
			used[p1.index]=1;
			for (ii=i-1; ii<=i+1; ii++) for (jj=j-1; jj<=j+1; jj++) for (kk=k-1; kk<=k+1; kk++){
				    // boost::numeric::ublas::vector<particle>::iterator nit(cell(i+n[0],j+n[1],k+n[2]).begin()), nitend(cell(i+n[0],j+n[1],k+n[2]).end());
				    for(int num2=0; num2<cell(ii,jj,kk).size(); num2++){
					p2=cell(ii,jj,kk)[num2];
					boost::numeric::ublas::vector<double> dr(3);
					dr=periodic_displacement(L_x,L_y,L_z,p1.r,p2.r);
					if(!used[p2.index] && boost::numeric::ublas::norm_2(dr)<=bond_cutoff){
					    bonds.push_back(bond(count,dr));
					    ++count;
					}
				    }//end num2
				}//end ii,jj,kk
		    }//end num1
		}
	std::cout<<"counted "<<count<<" bonds\n";
	std::cout<<"compute_bonds exited successfully\n";
    }
Exemple #12
0
void Hydrogen(long number){	  //boddy for hydrogen process

	
	sem_wait(&semaphores[LOCK]);	
	sem_wait(&semaphores[BOND_LOCK]);
	
	
	sem_wait(&semaphores[SHARED_MUTEX]);
	
	print_mutex_to_file(shared_counters[OPER_COUNTER]++, "H %ld\t: started\n", number);

	if(shared_counters[H_COUNTER] > 0 && shared_counters[OX_COUNTER] > 0){
		print_mutex_to_file(shared_counters[OPER_COUNTER]++, "H %ld\t: ready\n", number);
		shared_counters[H_COUNTER]--;
		shared_counters[OX_COUNTER]--;
		sem_post(&semaphores[H]);
		sem_post(&semaphores[OX]);
		sem_post(&semaphores[SHARED_MUTEX]);
		//sem_post(&semaphores[LOCK]);	
	}
	else{
		print_mutex_to_file(shared_counters[OPER_COUNTER]++, "H %ld\t: waiting\n", number);
		sem_post(&semaphores[LOCK]);
		sem_post(&semaphores[BOND_LOCK]);
		shared_counters[H_COUNTER]++;
		sem_post(&semaphores[SHARED_MUTEX]);
		sem_wait(&semaphores[H]);
		//sem_wait(&semaphores[BOND_LOCK]);
	}

	bond('H', number);

	sem_wait(&semaphores[SHARED_MUTEX]);
	shared_counters[BOND_END]++;
	if (shared_counters[BOND_END] == 3){
		shared_counters[BOND_END] = 0;
		sem_post(&semaphores[LOCK]);
	}
	sem_post(&semaphores[SHARED_MUTEX]);

	barrier_for_all();

	sem_wait(&semaphores[SHARED_MUTEX]);
	print_mutex_to_file(shared_counters[OPER_COUNTER]++, "H %ld\t: finished\n", number);
	sem_post(&semaphores[SHARED_MUTEX]);
}
void CHARMMParameters::parse_bond_line(const String& line,
                                       ResidueType curr_res_type,
                                       CHARMMResidueTopologyBase *residue,
                                       bool translate_names_to_pdb)
{
  Strings split_results;
  boost::split(split_results, line, boost::is_any_of(" \t"),
               boost::token_compress_on);
  if(split_results.size() < 3) return; // BOND line has at least 3 fields

  base::Vector<Bond> bonds;
  for(unsigned int i=1; i<split_results.size(); i+=2) {
    if(split_results[i][0] == '!') return;  // comments start
    Strings atom_names = get_atom_names(split_results.begin()+i,
                                        split_results.begin()+i+2,
                                        residue, translate_names_to_pdb);
    if (excess_patch_bond(atom_names, residue, translate_names_to_pdb)) {
      continue;
    }
    residue->add_bond(atom_names);
    // + connects to the next residue
    if (atom_names[0][0] == '+' || atom_names[1][0] == '+') continue;
    // skip 2-residue patch bonds
    if (atom_names[0][0] == '1' || atom_names[0][0] == '2'
        || atom_names[1][0] == '1' || atom_names[1][0] == '2') {
      continue;
    }
    // Ignore bonds to non-existent atoms
    if (AtomType::get_key_exists(atom_names[0])
        && AtomType::get_key_exists(atom_names[1])) {
      AtomType imp_atom_type1 = AtomType(atom_names[0]);
      AtomType imp_atom_type2 = AtomType(atom_names[1]);
      Bond bond(imp_atom_type1, imp_atom_type2);
      bonds.push_back(bond);
    }
  }

  if(residue_bonds_.find(curr_res_type) == residue_bonds_.end()) {
    residue_bonds_[curr_res_type] = bonds;
  } else {
    residue_bonds_[curr_res_type].insert(residue_bonds_[curr_res_type].end(),
                                         bonds.begin(), bonds.end());
  }
}
Exemple #14
0
List Factory::convert(Data::Geometry& geometry)
{
   List list;
   Atoms* atoms(new Atoms());
   Bonds* bonds(new Bonds());
   list.append(atoms);
   list.append(bonds);

   unsigned nAtoms(geometry.nAtoms());
   OpenBabel::OBMol obMol;
   obMol.BeginModify();
   AtomMap atomMap;
   
   for (unsigned i = 0; i < nAtoms; ++i) {
       unsigned Z(geometry.atomicNumber(i));
       qglviewer::Vec position(geometry.position(i));

       Atom* atom(new Atom(geometry.atomicNumber(i)));
       atom->setPosition(geometry.position(i));
       atoms->appendLayer(atom);

       OpenBabel::OBAtom* obAtom(obMol.NewAtom());
       obAtom->SetAtomicNum(Z);
       obAtom->SetVector(position.x, position.y, position.z);
       atomMap.insert(obAtom, atom);
   }

   obMol.SetTotalCharge(geometry.charge());
   obMol.SetTotalSpinMultiplicity(geometry.multiplicity());
   obMol.EndModify();
   obMol.ConnectTheDots();
   obMol.PerceiveBondOrders();

   for (OpenBabel::OBMolBondIter obBond(&obMol); obBond; ++obBond) {
       Atom* begin(atomMap.value(obBond->GetBeginAtom()));
       Atom* end(atomMap.value(obBond->GetEndAtom()));
       Bond* bond(new Bond(begin, end));
       bond->setOrder(obBond->GetBondOrder());
       bonds->appendLayer(bond);
   }

   return list;
}
Exemple #15
0
void oxygen(int I)
{
    sem_wait(&sems->count_inc);
    fflush(vars->h2o);
    fprintf(vars->h2o, "%d: O %d: started\n", vars->global_count, I);               //STARTED
    fflush(vars->h2o);
    vars->global_count++;
    sem_post(&sems->count_inc);


    sem_wait(&sems->mutex);

    vars->oxygen += 1;   

    if (vars->hydrogen >= 2)
    {
        sem_wait(&sems->count_inc);
        fflush(vars->h2o);
	fprintf(vars->h2o, "%d: O %d: ready\n", vars->global_count, I);             //READY
        fflush(vars->h2o);
	vars->global_count++;
        sem_post(&sems->count_inc);
 
        sem_post(&sems->hydroQueue);
        sem_post(&sems->hydroQueue);
        vars->hydrogen -= 2;
 
        sem_post(&sems->oxyQueue);
        vars->oxygen -= 1;
    }
    else
    {
	sem_wait(&sems->count_inc);
	fflush(vars->h2o);
	fprintf(vars->h2o, "%d: O %d: waiting\n", vars->global_count, I);               //WAITING
	fflush(vars->h2o);
	vars->global_count++;
	sem_post(&sems->count_inc);

        sem_post(&sems->mutex);
    }

    sem_wait(&sems->oxyQueue);
   


    bond("O", I);


    //reusable barrier for three atoms
    sem_wait(&sems->bar_ct_mtx);
    vars->count++;
    if (vars->count == 3)
    {
	sem_wait(&sems->turnstile2);
	sem_post(&sems->turnstile);
    }
    sem_post(&sems->bar_ct_mtx);

    sem_wait(&sems->turnstile);
    sem_post(&sems->turnstile);




    sem_wait(&sems->bar_ct_mtx2);
    vars->count--;
    if (vars->count == 0)
    {
	sem_wait(&sems->turnstile);
	sem_post(&sems->turnstile2);
    }
    sem_post(&sems->bar_ct_mtx2);

    sem_wait(&sems->turnstile2);
    sem_post(&sems->turnstile2);
    sem_post(&sems->mutex);
    //reusable barrier for three atoms

    sem_wait(&sems->barrier_counter);
    vars->barrier_count++;
    //printf("barrier_count: %d\n", vars->barrier_count);
    sem_post(&sems->barrier_counter);
 
    if (vars->barrier_count == vars->N * 3) sem_post(&sems->barrier);
 
    sem_wait(&sems->barrier);
    sem_post(&sems->barrier);
    


 
    sem_wait(&sems->count_inc);
    fflush(vars->h2o);
    fprintf(vars->h2o, "%d: O %d: finished\n", vars->global_count, I);              //FINISHED
    fflush(vars->h2o);
    vars->global_count++;
    sem_post(&sems->count_inc);

    free_resources();
    _Exit(0);
 
} //oxygen
Exemple #16
0
void AudioOutput::setSource (AudioSource* source)
{
  ResamplingAudioSource* resampler = new ResamplingAudioSource (source, true);
  m_queue.call (bond (&AudioOutput::doSetSource, this, resampler));
}
Exemple #17
0
void AudioOutput::setFilter (Dsp::Filter* filter)
{
  m_queue.call (bond (&AudioOutput::doSetFilter, this, filter));
}
Exemple #18
0
void AudioOutput::setGain (float gainDb)
{
  m_queue.call (bond (&AudioOutput::doSetGain, this, Decibels::decibelsToGain(gainDb)));
}
Exemple #19
0
void AudioOutput::setTempo (float tempo)
{
  m_queue.call (bond (&AudioOutput::doSetTempo, this, tempo));
}
Exemple #20
0
void AudioOutput::setFilterParameters (Dsp::Params parameters)
{
  m_queue.call (bond (&AudioOutput::doSetFilterParameters, this, parameters));
}
Exemple #21
0
void AudioOutput::resetFilter ()
{
  m_queue.call (bond (&AudioOutput::doResetFilter, this));
}
Exemple #22
0
//hydrogen
void hydrogen(int I)
{
    sem_wait(&sems->count_inc);
    fflush(vars->h2o);
    fprintf(vars->h2o, "%d: H %d: started\n", vars->global_count, I);               //STARTED
    fflush(vars->h2o);
    vars->global_count++;
    sem_post(&sems->count_inc);
 


    sem_wait(&sems->mutex);
   
    vars->hydrogen += 1; 

    if (vars->hydrogen >= 2 && vars->oxygen >= 1)
    {
	sem_wait(&sems->count_inc);
        fflush(vars->h2o);
	fprintf(vars->h2o, "%d: H %d: ready\n", vars->global_count, I);             //READY
        fflush(vars->h2o);
	vars->global_count++;
        sem_post(&sems->count_inc);

        sem_post(&sems->hydroQueue);
        sem_post(&sems->hydroQueue);
        vars->hydrogen -= 2;
 
        sem_post(&sems->oxyQueue);
        vars->oxygen -= 1;
    }
    else
    {
	sem_wait(&sems->count_inc);
	fflush(vars->h2o);
	fprintf(vars->h2o, "%d: H %d: waiting\n", vars->global_count, I);               //WAITING
	fflush(vars->h2o);
	vars->global_count++;
	sem_post(&sems->count_inc);

        sem_post(&sems->mutex);
    }

 
    
    sem_wait(&sems->hydroQueue);


    bond("H", I);
 

    //reusable barrier for three atoms, when three atoms are boding into h2o molecule, 
    //no other action except 'started' may happen
    sem_wait(&sems->bar_ct_mtx);
    vars->count++;
    if (vars->count == 3)
    {
	sem_wait(&sems->turnstile2);
	sem_post(&sems->turnstile);
    }
    sem_post(&sems->bar_ct_mtx);

    sem_wait(&sems->turnstile);
    sem_post(&sems->turnstile);


    //kriticka zona bariery


    sem_wait(&sems->bar_ct_mtx2);
    vars->count--;
    if (vars->count == 0)
    {
	sem_wait(&sems->turnstile);
	sem_post(&sems->turnstile2);
    }
    sem_post(&sems->bar_ct_mtx2);

    sem_wait(&sems->turnstile2);
    sem_post(&sems->turnstile2);
    //reusable barrier for three atoms



    sem_wait(&sems->barrier_counter);
    vars->barrier_count++;
    //printf("barrier_count: %d\n", vars->barrier_count);
    sem_post(&sems->barrier_counter);
 
    if (vars->barrier_count == vars->N * 3) sem_post(&sems->barrier);
    
    sem_wait(&sems->barrier);
    sem_post(&sems->barrier);


    //barrier for all atoms, befor finish
    sem_wait(&sems->count_inc);
    fflush(vars->h2o);
    fprintf(vars->h2o, "%d: H %d: finished\n", vars->global_count, I);              //FINISHED
    fflush(vars->h2o);
    vars->global_count++;
    sem_post(&sems->count_inc);
    //barrier for all atoms

    free_resources();
    _Exit(0);
 
} //hydrogen
double FluidMixture::computeUniformEx(const std::vector<double>& Nmol, std::vector<double>& Phi_Nmol) const
{	//--------- Compute the site densities ----------
	std::vector<double> N(nDensities);
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		for(unsigned i=0; i<c.molecule.sites.size(); i++)
			N[c.offsetDensity + i] += Nmol[ic] * c.molecule.sites[i]->positions.size();
	}

	EnergyComponents phi; std::vector<double> Phi_N(nDensities);

	//-------- Mean field coulomb -------- (No contribution in uniform fluid)

	//-------- Hard sphere/bonding -----------
	double n0=0.0, n1=0.0, n2=0.0, n3=0.0;
	std::vector<double> n0mol(component.size(), 0.0); //partial n0 for molecules that need bonding corrections
	std::vector<int> n0mult(component.size(), 0); //number of sites which contribute to n0 for each molecule
	std::vector<std::map<double,int> > bond(component.size()); //sets of bonds for each molecule
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		bond[ic] = c.molecule.getBonds();
		for(unsigned i=0; i<c.molecule.sites.size(); i++)
		{	const Molecule::Site& s = *(c.molecule.sites[i]);
			if(s.Rhs)
			{	double Nsite = N[c.offsetDensity+i];
				n0mult[ic] += s.positions.size();
				n0mol[ic]  += s.w0(0)  * Nsite;
				n1         += s.w1(0)  * Nsite;
				n2         += s.w2(0)  * Nsite;
				n3         += s.w3(0)  * Nsite;
			}
		}
		n0 += n0mol[ic];
	}
	if(n0)
	{	double Phi_n0=0.0, Phi_n1=0.0, Phi_n2=0.0, Phi_n3=0.0;
		phi["MixedFMT"] = T * phiFMTuniform(n0, n1, n2, n3, Phi_n0, Phi_n1, Phi_n2, Phi_n3);
		//Bonding corrections:
		for(unsigned ic=0; ic<component.size(); ic++)
		{	const FluidComponent& c = *component[ic];
			double Phi_n0mol=0.0;
			for(const auto& b: bond[ic])
				phi["Bonding"] += T * phiBondUniform(b.first, b.second*1.0/n0mult[ic],
					n0mol[ic], n2, n3, Phi_n0mol, Phi_n2, Phi_n3);
			if(Phi_n0mol)
			{	//Propagate gradient w.r.t n0mol[ic] to the site densities:
				for(unsigned i=0; i<c.molecule.sites.size(); i++)
				{	const Molecule::Site& s = *(c.molecule.sites[i]);
					if(s.Rhs) Phi_N[c.offsetDensity+i] += T * (s.w0(0)  * Phi_n0mol);
				}
			}
		}
		//Convert FMT weighted gradients to site density gradients:
		for(const FluidComponent* c: component)
		{	for(unsigned i=0; i<c->molecule.sites.size(); i++)
			{	const Molecule::Site& s = *(c->molecule.sites[i]);
				if(s.Rhs)
				{	double& Phi_Nsite = Phi_N[c->offsetDensity+i];
					Phi_Nsite += T * (s.w0(0)  * Phi_n0);
					Phi_Nsite += T * (s.w1(0)  * Phi_n1);
					Phi_Nsite += T * (s.w2(0)  * Phi_n2);
					Phi_Nsite += T * (s.w3(0)  * Phi_n3);
				}
			}
		}
	}

	//---------- Excess functionals --------------
	for(const FluidComponent* c: component) if(c->fex)
		phi["Fex("+c->molecule.name+")"] += c->fex->computeUniform(&N[c->offsetDensity], &Phi_N[c->offsetDensity]);

	//--------- Mixing functionals --------------
	for(const Fmix* fmix: fmixArr)
		phi["Fmix("+fmix->getName()+")"] += fmix->computeUniform(N, Phi_N);

	//--------- Convert site density gradients to molecular density gradients ---------
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		Phi_Nmol[ic] = 0.0;
		for(unsigned i=0; i<c.molecule.sites.size(); i++)
			Phi_Nmol[ic] += Phi_N[c.offsetDensity+i] * c.molecule.sites[i]->positions.size();;
	}

	if (verboseLog) phi.print(globalLog, true, "\t\t\t\t%15s = %12.4le\n"); //Uncomment when debugging to get contributions
	return phi;
}
double FluidMixture::operator()(const ScalarFieldArray& indep, ScalarFieldArray& Phi_indep, Outputs outputs) const
{	static StopWatch watch("FluidMixture::operator()"); watch.start();

	//logPrintf("indep.size: %d nIndep: %d\n",indep.size(),nIndep);
	myassert(indep.size()==get_nIndep());

	//---------- Compute site densities from the independent variables ---------
	ScalarFieldTildeArray Ntilde(nDensities); //site densities (in reciprocal space)
	std::vector< vector3<> > P0(component.size()); //polarization densities G=0
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		ScalarFieldArray N(c.molecule.sites.size());
		c.idealGas->getDensities(&indep[c.offsetIndep], &N[0], P0[ic]);
		for(unsigned i=0; i<c.molecule.sites.size(); i++)
		{	//Replace negative densities with 0:
			double Nmin, Nmax;
			callPref(eblas_capMinMax)(gInfo.nr, N[i]->dataPref(), Nmin, Nmax, 0.);
			//store site densities in fourier space
			Ntilde[c.offsetDensity+i] = J(N[i]);
			N[i] = 0; //Really skimp on memory!
		}
	}

	//----------- Handle density constraints ------------
	std::vector<double> Nscale(component.size(), 1.0); //density scale factor that satisfies the constraint
	std::vector<double> Ntot_c; //vector of total number of molecules for each component
	std::vector<double> Nscale_Qfixed(component.size(), 0.); //derivative of Nscale w.r.t the fixed charge
	std::vector<std::vector<double> > Nscale_N0(component.size(), std::vector<double>(component.size(),0.0)); //jacobian of Nscale w.r.t the uncorrected molecule counts
	std::vector<string> names; //list of molecule names
	
	//Find fixed N and charged species:
	double Qfixed = 0.0;
	if(rhoExternal) Qfixed += integral(rhoExternal);
	std::vector<std::pair<double,double> > N0Q;
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		double Qmolecule = c.molecule.getCharge();
		if(c.Nnorm>0 || Qmolecule)
		{	double N0 = integral(Ntilde[c.offsetDensity])/c.molecule.sites[0]->positions.size();
			if(c.Nnorm>0)
			{	Nscale[ic] = c.Nnorm/N0;
				Nscale_N0[ic][ic] = -c.Nnorm/pow(N0,2);
				Qfixed += Qmolecule*c.Nnorm;
			}
			else
			{	N0Q.push_back(std::make_pair(N0, Qmolecule));
				names.push_back(c.molecule.name);
			}
		}
	}
	//Find the betaV (see Qtot()) that makes the unit cell neutral
	if(N0Q.size()==0)
	{	if(fabs(Qfixed)>fabs(Qtol))
			die("Unit cell has a fixed net charge %le,"
				"and there are no free charged species to neutralize it.\n", Qfixed);
	}
	else
	{	double Qprime, Qcell, betaV=0.0;
		if(Qfixed+Qtot(-HUGE_VAL,Qprime,N0Q)<0)
			die("Unit cell will always have a net negative charge (no free positive charges).\n")
		if(Qfixed+Qtot(+HUGE_VAL,Qprime,N0Q)>0)
			die("Unit cell will always have a net positive charge (no free negative charges).\n")

		for(int iter=0; iter<10; iter++) //while(1)
		{	Qcell = Qfixed+Qtot(betaV,Qprime,N0Q,&names,&gInfo,verboseLog);
			if(verboseLog) logPrintf("betaV = %le, Qcell = %le, Qprime = %le\n", betaV, Qcell, Qprime);
			if(fabs(Qcell)<fabs(Qtol)) break;	
			if(std::isnan(Qcell)) 
			  { betaV=0.0; break;}
			betaV -= Qcell/Qprime; //Newton-Raphson update
			
		}
		for(unsigned ic=0; ic<component.size(); ic++)
		{	const FluidComponent& ci = *component[ic];
			double Qi = ci.molecule.getCharge();
			if(Qi && ci.Nnorm<=0)
			{	Nscale[ic] = exp(-Qi*betaV);
				Nscale_Qfixed[ic] = exp(-Qi*betaV) * Qi / Qprime;
				for(unsigned jc=0; jc<component.size(); jc++)
				{	const FluidComponent& cj = *component[jc];
					double Qj = cj.molecule.getCharge();
					if(Qj && cj.Nnorm<=0)
						Nscale_N0[ic][jc] += Qi*Qj*exp(-(Qi+Qj)*betaV)/Qprime;
				}
			}
		}
	}
	std::vector<double> Phi_Nscale(component.size(), 0.0); //accumulate explicit derivatives w.r.t Nscale here

	//Apply the scale factors to the site densities
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		for(unsigned i=0; i<c.molecule.sites.size(); i++)
			Ntilde[c.offsetDensity+i] *= Nscale[ic];
		P0[ic] *= Nscale[ic];
		Ntot_c.push_back(integral(Ntilde[c.offsetDensity]));
	}

	EnergyComponents Phi; //the grand free energy (with component information)
	ScalarFieldTildeArray Phi_Ntilde(nDensities); //gradients (functional derivative) w.r.t reciprocal space site densities
	nullToZero(Phi_Ntilde,gInfo);
	std::vector< vector3<> > Phi_P0(component.size()); //functional derivative w.r.t polarization density G=0
	VectorFieldTilde Phi_epsMF; //functional derivative w.r.t mean field electric field
	
	//G=0 fix for mismatch in fluid-fluid vs. fluid-electron charge kernels
	//We do this AFTER we have applied the appropriate scale factors
	if( N0Q.size() && (!useMFKernel)) //if we have charged species in our fluid, and are using mismatched charge kernels
	{
	  	for(unsigned ic=0; ic<component.size(); ic++)
		{	const FluidComponent& c = *component[ic];
		        for(unsigned i=0; i<c.molecule.sites.size(); i++)
			  { 
			    const Molecule::Site& s = *(c.molecule.sites[i]);
			    Phi["Gzero"] += Qfixed*(Ntot_c[ic]/gInfo.detR-c.idealGas->Nbulk)*s.positions.size()*s.deltaS;
			    Phi_Ntilde[c.offsetDensity+i]->data()[0] += (1.0/gInfo.dV) * (Qfixed*s.deltaS);
			  }
		}
	}

	//--------- Compute the (scaled) mean field coulomb interaction --------
	{	ScalarFieldTilde rho; //total charge density
		ScalarFieldTilde rhoMF; //effective charge density for mean-field term
		bool needRho = rhoExternal || outputs.Phi_rhoExternal;
		
		VectorFieldTilde epsMF = polarizable ? J(VectorField(&indep[nIndepIdgas])) : 0; //mean field electric field
		vector3<> P0tot;
		
		for(unsigned ic=0; ic<component.size(); ic++)
		{	const FluidComponent& c = *component[ic];
			for(unsigned i=0; i<c.molecule.sites.size(); i++)
			{	const Molecule::Site& s = *(c.molecule.sites[i]);
				if(s.chargeKernel)
				{	if(needRho) rho += s.chargeKernel * Ntilde[c.offsetDensity+i];
					rhoMF += s.chargeKernel(0) * (c.molecule.mfKernel * Ntilde[c.offsetDensity+i]);
				}
				//Polarization contributions:
				if(polarizable && s.polKernel)
				{	
					#define Polarization_Compute_Pi_Ni \
						VectorField Pi = (Cpol*s.alpha) * I(c.molecule.mfKernel*epsMF - (rhoExternal ? gradient(s.polKernel*coulomb(rhoExternal)) : 0)); \
						ScalarField Ni = I(Ntilde[c.offsetDensity+i]);
					Polarization_Compute_Pi_Ni
					
					ScalarField Phi_Ni = (0.5/(Cpol*s.alpha))*lengthSquared(Pi);
					Phi["Apol"] += gInfo.dV * dot(Ni, Phi_Ni);
					//Derivative contribution to site densities:
					Phi_Ntilde[c.offsetDensity+i] += Idag(Phi_Ni); Phi_Ni=0;
					//Update contributions to bound charge:
					VectorFieldTilde NPtilde = J(Ni * Pi); Pi=0; Ni=0;
					ScalarFieldTilde divNPbar;
					if(needRho) rho -= s.polKernel*divergence(NPtilde);
					VectorFieldTilde NPbarMF = c.molecule.mfKernel*NPtilde; NPtilde=0;
					rhoMF -= divergence(NPbarMF);
					Phi_epsMF += gInfo.nr * NPbarMF;
					P0tot += getGzero(NPbarMF);
				}
			}
			P0tot += P0[ic];
		}
		
		if(rhoMF)
		{	//External charge interaction:
			ScalarFieldTilde Phi_rho;
			ScalarFieldTilde Phi_rhoMF;
			if(needRho)
			{	if(rhoExternal)
				{	
				  ScalarFieldTilde OdExternal = O(coulomb(rhoExternal));
				  if (!useMFKernel)
				   {	
			  	       Phi["ExtCoulomb"] += dot(rho, OdExternal);
				       Phi_rho += OdExternal;
				   }
				   if (useMFKernel)
				   {
				       Phi["ExtCoulomb"] += dot(rhoMF, OdExternal);   
				       Phi_rhoMF += OdExternal; 
				   }
				}
				if(outputs.Phi_rhoExternal) 
				{
				  if (!useMFKernel) *outputs.Phi_rhoExternal = coulomb(rho);
				  if (useMFKernel) *outputs.Phi_rhoExternal = coulomb(rhoMF);
				}
			}
		
			//Mean field contributions:
			{	ScalarFieldTilde OdMF = O(coulomb(rhoMF)); //mean-field electrostatic potential
				Phi["Coulomb"] += 0.5*dot(rhoMF, OdMF);
				Phi_rhoMF += OdMF;
			}
			
			//Polarization density interactions:
			if(outputs.electricP) *outputs.electricP = P0tot * gInfo.detR;
			//--- corrections for net dipole in cell:
			vector3<> Phi_P0tot = (4*M_PI*gInfo.detR) * P0tot;
			Phi["PsqCell"] += 0.5 * dot(Phi_P0tot, P0tot); 
			//--- external electric field interactions:
			Phi["ExtCoulomb"] -= gInfo.detR * dot(Eexternal, P0tot);
			Phi_P0tot -= gInfo.detR * Eexternal;
			
			//Propagate gradients:
			for(unsigned ic=0; ic<component.size(); ic++)
			{	const FluidComponent& c = *component[ic];
				for(unsigned i=0; i<c.molecule.sites.size(); i++)
				{	const Molecule::Site& s = *(c.molecule.sites[i]);
					if(s.chargeKernel)
					{	if(Phi_rho) Phi_Ntilde[c.offsetDensity+i] += (1./gInfo.dV) * (s.chargeKernel * Phi_rho);
						Phi_Ntilde[c.offsetDensity+i] += (s.chargeKernel(0)/gInfo.dV) * (c.molecule.mfKernel * Phi_rhoMF);
					}
					//Polarization contributions:
					if(polarizable && s.polKernel)
					{	VectorFieldTilde Phi_NPtilde = gradient(c.molecule.mfKernel*Phi_rhoMF + (needRho ? s.polKernel*Phi_rho : 0));
						setGzero(Phi_NPtilde, getGzero(Phi_NPtilde) + Phi_P0tot);
						VectorField Phi_NP = Jdag(Phi_NPtilde); Phi_NPtilde=0;
						//propagate gradients from NP to N, epsMF and rhoExternal:
						Polarization_Compute_Pi_Ni
						#undef Polarization_Compute_Pi_Ni
						// --> via Ni
						ScalarField Phi_Ni; for(int k=0; k<3; k++) Phi_Ni += Phi_NP[k]*Pi[k];
						Phi_Ntilde[c.offsetDensity+i] += (1./gInfo.dV) * Idag(Phi_Ni); Phi_Ni=0;
						// --> via Pi
						VectorFieldTilde Phi_PiTilde = Idag(Phi_NP * Ni); Phi_NP=0;
						Phi_epsMF += (Cpol*s.alpha/gInfo.dV)*(c.molecule.mfKernel*Phi_PiTilde);
					}
				}
				Phi_P0[ic] += (1./gInfo.detR) * Phi_P0tot; //convert to functional derivative
			}
		}
	}
	
	//--------- Hard sphere mixture and bonding -------------
	{	//Compute the FMT weighted densities:
		ScalarFieldTilde n0tilde, n1tilde, n2tilde, n3tilde, n1vTilde, n2mTilde;
		std::vector<ScalarField> n0mol(component.size(), 0); //partial n0 for molecules that need bonding corrections
		std::vector<int> n0mult(component.size(), 0); //number of sites which contribute to n0 for each molecule
		std::vector<std::map<double,int> > bond(component.size()); //sets of bonds for each molecule
		bool bondsPresent = false; //whether bonds are present for any molecule
		for(unsigned ic=0; ic<component.size(); ic++)
		{	const FluidComponent& c = *component[ic];
			bond[ic] = c.molecule.getBonds();
			ScalarFieldTilde n0molTilde;
			for(unsigned i=0; i<c.molecule.sites.size(); i++)
			{	const Molecule::Site& s = *(c.molecule.sites[i]);
				if(s.Rhs)
				{	const ScalarFieldTilde& Nsite = Ntilde[c.offsetDensity+i];
					n0mult[ic] += s.positions.size();
					n0molTilde += s.w0  * Nsite;
					n1tilde    += s.w1  * Nsite;
					n2tilde    += s.w2  * Nsite;
					n3tilde    += s.w3  * Nsite;
					n1vTilde   += s.w1v * Nsite;
					n2mTilde   += s.w2m * Nsite;
				}
			}
			if(n0molTilde) n0tilde += n0molTilde;
			if(bond[ic].size())
			{	n0mol[ic] = I(n0molTilde);
				bondsPresent = true;
			}
		}
		if(n0tilde) //at least one sphere in the mixture
		{	ScalarField n0 = I(n0tilde); n0tilde=0;
			ScalarField n1 = I(n1tilde); n1tilde=0;
			ScalarField n2 = I(n2tilde); n2tilde=0;
			ScalarField Phi_n0, Phi_n1, Phi_n2; ScalarFieldTilde Phi_n3tilde, Phi_n1vTilde, Phi_n2mTilde;
			//Compute the sphere mixture free energy:
			Phi["MixedFMT"] += T * PhiFMT(n0, n1, n2, n3tilde, n1vTilde, n2mTilde,
				Phi_n0, Phi_n1, Phi_n2, Phi_n3tilde, Phi_n1vTilde, Phi_n2mTilde);
			//Bonding corrections if required
			if(bondsPresent)
			{	for(unsigned ic=0; ic<component.size(); ic++)
				{	const FluidComponent& c = *component[ic];
					ScalarField Phi_n0mol;
					for(const auto& b: bond[ic])
						Phi["Bonding"] += T * PhiBond(b.first, b.second*1./n0mult[ic],
							n0mol[ic], n2, n3tilde, Phi_n0mol, Phi_n2, Phi_n3tilde);
					if(Phi_n0mol)
					{	//Propagate gradient w.r.t n0mol[ic] to the site densities:
						ScalarFieldTilde Phi_n0molTilde = Idag(Phi_n0mol);
						for(unsigned i=0; i<c.molecule.sites.size(); i++)
						{	const Molecule::Site& s = *(c.molecule.sites[i]);
							if(s.Rhs)
								Phi_Ntilde[c.offsetDensity+i] += T * (s.w0  * Phi_n0molTilde);
						}
					}
				}
			}
			//Accumulate gradients w.r.t weighted densities to site densities:
			ScalarFieldTilde Phi_n0tilde = Idag(Phi_n0); Phi_n0=0;
			ScalarFieldTilde Phi_n1tilde = Idag(Phi_n1); Phi_n1=0;
			ScalarFieldTilde Phi_n2tilde = Idag(Phi_n2); Phi_n2=0;
			for(const FluidComponent* c: component)
			{	for(unsigned i=0; i<c->molecule.sites.size(); i++)
				{	const Molecule::Site& s = *(c->molecule.sites[i]);
					if(s.Rhs)
					{	ScalarFieldTilde& Phi_Nsite = Phi_Ntilde[c->offsetDensity+i];
						Phi_Nsite += T * (s.w0  * Phi_n0tilde);
						Phi_Nsite += T * (s.w1  * Phi_n1tilde);
						Phi_Nsite += T * (s.w2  * Phi_n2tilde);
						Phi_Nsite += T * (s.w3  * Phi_n3tilde);
						Phi_Nsite += T * (s.w1v * Phi_n1vTilde);
						Phi_Nsite += T * (s.w2m * Phi_n2mTilde);
					}
				}
			}
		}
	}

	//---------- Excess functionals --------------
	for(const FluidComponent* c: component) if(c->fex)
		Phi["Fex("+c->molecule.name+")"] += c->fex->compute(&Ntilde[c->offsetDensity], &Phi_Ntilde[c->offsetDensity]);

	//--------- Mixing functionals --------------
	for(const Fmix* fmix: fmixArr)
		Phi["Fmix("+fmix->getName()+")"] += fmix->compute(Ntilde, Phi_Ntilde);

	//--------- PhiNI ---------
	nullToZero(Phi_Ntilde, gInfo);
	if(outputs.N) outputs.N->resize(nDensities);
	//Put the site densities and gradients back in real space
	ScalarFieldArray N(nDensities);
	ScalarFieldArray Phi_N(nDensities);
	for(unsigned i=0; i<nDensities; i++)
	{	N[i] = I(Ntilde[i]); Ntilde[i]=0;
		Phi_N[i] = Jdag(Phi_Ntilde[i]); Phi_Ntilde[i] = 0;
		if(outputs.N) (*outputs.N)[i] = N[i]; //Link site-density to return pointer if necessary
	}
	//Estimate psiEff based on gradients, if requested
	if(outputs.psiEff)
	{	outputs.psiEff->resize(nDensities);
		for(const FluidComponent* c: component)
			for(unsigned i=0; i<c->molecule.sites.size(); i++)
			{	ScalarField& psiCur = outputs.psiEff->at(c->offsetDensity+i);
				psiCur = Phi_N[c->offsetDensity+i] + c->idealGas->V[i];
				if(i==0) psiCur -= c->idealGas->mu / c->molecule.sites[0]->positions.size();
				psiCur *= (-1./T);
			}
	}
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		Phi["PhiNI("+c.molecule.name+")"] +=
			c.idealGas->compute(&indep[c.offsetIndep], &N[c.offsetDensity], &Phi_N[c.offsetDensity], Nscale[ic], Phi_Nscale[ic]);

		//Fixed N correction to entropy:
		if(Nscale[ic]!=1.0)
		{	double deltaTs = T*log(Nscale[ic]) / c.molecule.sites[0]->positions.size();
			Phi_N[c.offsetDensity] += deltaTs;
			Phi["PhiNI("+c.molecule.name+")"] += integral(N[c.offsetDensity])*deltaTs;
		}
	}
	//Add in the implicit contributions to Phi_Nscale
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& ci = *component[ic];
		bool anyNonzero=false;
		for(unsigned jc=0; jc<component.size(); jc++)
			if(Nscale_N0[ic][jc])
				anyNonzero=true;
		if(anyNonzero)
		{	Phi_Nscale[ic] += gInfo.detR*dot(P0[ic], Phi_P0[ic])/ Nscale[ic];
			for(unsigned i=0; i<ci.molecule.sites.size(); i++)
				Phi_Nscale[ic] += gInfo.dV*dot(N[ci.offsetDensity+i], Phi_N[ci.offsetDensity+i])/ Nscale[ic];
		}
	}
	//Propagate gradients from Nscale to N:
	for(unsigned jc=0; jc<component.size(); jc++)
	{	const FluidComponent& cj = *component[jc];
		double Phi_Ncontrib = 0.0;
		for(unsigned ic=0; ic<component.size(); ic++)
			if(Nscale_N0[ic][jc])
				Phi_Ncontrib += Phi_Nscale[ic] * Nscale_N0[ic][jc];
		if(Phi_Ncontrib)
			Phi_N[cj.offsetDensity] += Phi_Ncontrib / (Nscale[jc] * cj.molecule.sites[0]->positions.size());
	}

	//Propagate gradients from Phi_N and Phi_P to Phi_indep
	Phi_indep.resize(get_nIndep());
	for(unsigned ic=0; ic<component.size(); ic++)
	{	const FluidComponent& c = *component[ic];
		c.idealGas->convertGradients(&indep[c.offsetIndep], &N[c.offsetDensity],
			&Phi_N[c.offsetDensity], Phi_P0[ic], &Phi_indep[c.offsetIndep], Nscale[ic]);
	}
	for(unsigned k=nIndepIdgas; k<get_nIndep(); k++) Phi_indep[k] = Jdag(Phi_epsMF[k-nIndepIdgas]);
	
	//Propagate gradients from Nscale to Qfixed / rhoExternal (Natural G=0 solution)
	if(outputs.Phi_rhoExternal)
	{	double Phi_Qfixed = 0.;
		for(unsigned ic=0; ic<component.size(); ic++)
		{
			Phi_Qfixed += Phi_Nscale[ic] * Nscale_Qfixed[ic];
			if (N0Q.size() && (!useMFKernel))
		        {
				const FluidComponent& c = *component[ic];
				for(unsigned i=0; i<c.molecule.sites.size(); i++)
				{ 
				 	//Correction to lambda from charge kernel mismatch
					  const Molecule::Site& s = *(c.molecule.sites[i]);
					  double lambda_s =  (Ntot_c[ic]/gInfo.detR-c.idealGas->Nbulk)*s.deltaS*s.positions.size();
					  if(verboseLog) logPrintf("Charge kernel mismatch correction for site %s of molecule %s: %lg\n",
					  s.name.c_str(),c.molecule.name.c_str(),lambda_s);
					  Phi_Qfixed += lambda_s;
				}
				 if(verboseLog) logPrintf("Total number of molecules of type %s: %lg\n",c.molecule.name.c_str(),Ntot_c[ic]);
		        }
		}
		nullToZero(*outputs.Phi_rhoExternal, gInfo);
		(*outputs.Phi_rhoExternal)->setGzero(Phi_Qfixed);
	}
	
	Phi["+pV"] += p * gInfo.detR; //background correction

	if(verboseLog) Phi.print(globalLog, true, "\t\t\t\t%15s = %25.16lf\n");
	if(outputs.Phi) *(outputs.Phi) = Phi;
	
	Phi_indep *= gInfo.dV; //convert functional derivative to partial derivative
	watch.stop();
	return Phi;
}
bool TissueState::parseFromTrackedCellsFile(const string FileName, const string OriginalFileName) {
  cleanUp();
  
  // load images
  QtRasterImage image(FileName.c_str());
  if(!image.valid()) {
    return false;
  }
  QtRasterImage original(OriginalFileName.c_str());
  if(!original.valid()) {
    return false;
  }
  // prepare pixel frames
  PixelFrame frame(image);
  PixelFrame originalFrame(original);
  
  TextProgressBar bar;
  
  // loop through all pixels of the image
  Pixel p(frame);
  PixelValue lastValue=p.data();
  while(true) {
    Pixel lastP(p);
    ++p;
    // done?
    if(!p.inCanvas()) { break; }
    // get pixel value
    PixelValue curValue=p.data();
    // value changes?
    if(lastValue!=curValue) {
      // was bond before?
      if(lastValue==Pixel::BondValue) {
        // -> curValue corresponds to a cell id and lastP sits on a boundary pixel
        CellIndex id = curValue;
        // cell not yet created and not among the ignored cells?
        if((_cells.count(id)==0) && (_ignoredCells.count(id)==0)) {
          if(!addCell(id, lastP, originalFrame)) {
            return false;
          }
        }
      }
      lastValue = curValue;
    }
    bar.update(p.fractionOfCanvas());
  }
  bar.done(true);
  
  // clear unneeded data
  _vertexMap.clear();
  _directedBondMap.clear();
  
  // remove directed bonds without cell (created in addCell as old conjugated bonds; this was needed for the sorting within vertices)
  std::stack<DirectedBond*> toBeRemoved;
  for(TissueState::BondIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
    if(!bond(it)->cell) {
      toBeRemoved.push(bond(it));
    }
  }
  while(!toBeRemoved.empty()) {
    removeBondWithoutCell(toBeRemoved.top());
    toBeRemoved.pop();
  }

  
  return true;
}
bool TissueState::exportToDbTables(const int ImageHeight, ofstream& framesFile, ofstream &verticesFile, ofstream &cellsFile, ofstream &ignoredCellsFile, ofstream &undirectedBondsFile, ofstream &directedBondsFile, unsigned long &lastVid, unsigned long &lastDbid, unsigned long &lastUbid) const {
  if(contains(Cell::VoidCellId)) {
    std::cout << "Found void cell id " << Cell::VoidCellId << " in frame " << _frameNumber << "!" << std::endl;
    return false;
  }
  
  // add data to frames table
  framesFile << _frameNumber << LogFile::DataSeparator << _time << '\n';
  if(framesFile.bad()) {
    std::cout << "Error writing frame data!" << std::endl;
    return false;
  }
  
  // add data to vertex table and generate map: vertex pointer -> vid
  std::map<Vertex*,unsigned long> vertexPointerToVid;
  for(int i=0; i<numberOfVertices(); ++i) {
    Vertex *v = vertex(i);
    ++lastVid;
    vertexPointerToVid[v] = lastVid;
    // write data:
    verticesFile << _frameNumber << LogFile::DataSeparator << lastVid << LogFile::DataSeparator << v->r.x() << LogFile::DataSeparator << ImageHeight-1-v->r.y() << '\n';
    if(verticesFile.bad()) {
      std::cout << "Error writing vertex data!" << std::endl;
      return false;
    }
  }
  
  // add data to cell table and generate map for bond sorting within cells
  std::map<DirectedBond*,DirectedBond*> leftBondSeenFromCellMap;
  // void cell
  cellsFile << _frameNumber << LogFile::DataSeparator << Cell::VoidCellId
          << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 
          << LogFile::DataSeparator << -1 << LogFile::DataSeparator << -1 << LogFile::DataSeparator << 0 
          << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 
          << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 
          << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 
          << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 << LogFile::DataSeparator << 0 
          << '\n';
  // other cells
  for(TissueState::CellConstIterator it=beginCellIterator(); it!=endCellIterator(); ++it) {
    Cell *c = cell(it);
    for(unsigned int j=0; j<c->bonds.size(); ++j) {
      leftBondSeenFromCellMap[c->bonds[j]] = c->bonds[(j+1)%c->bonds.size()];
    }
    // write data; revert signs of nematic xy components such that the values in the .dat files corresponds to a coordinate system with the y axis pointing upwards
    cellsFile << _frameNumber << LogFile::DataSeparator << c->id
            << LogFile::DataSeparator << (int)c->duringTransitionBefore << LogFile::DataSeparator << (int)c->duringTransitionAfter << LogFile::DataSeparator << c->daughter
            << LogFile::DataSeparator << c->r.x() << LogFile::DataSeparator << ImageHeight-1-c->r.y() << LogFile::DataSeparator << c->area
            << LogFile::DataSeparator << c->elongation.c1() << LogFile::DataSeparator << -c->elongation.c2()
            << LogFile::DataSeparator << c->polarityR.c1() << LogFile::DataSeparator << -c->polarityR.c2() << LogFile::DataSeparator << c->intIntensityR
            << LogFile::DataSeparator << c->polarityG.c1() << LogFile::DataSeparator << -c->polarityG.c2() << LogFile::DataSeparator << c->intIntensityG
            << LogFile::DataSeparator << c->polarityB.c1() << LogFile::DataSeparator << -c->polarityB.c2() << LogFile::DataSeparator << c->intIntensityB
            << '\n';
    if(cellsFile.bad()) {
      std::cout << "Error writing cell data!" << std::endl;
      return false;
    }
  }

  // ignored cells
  for(set<CellIndex>::const_iterator it=_ignoredCells.begin(); it!=_ignoredCells.end(); ++it) {
    // write data:
    ignoredCellsFile << _frameNumber << LogFile::DataSeparator << *it << '\n';
    if(ignoredCellsFile.bad()) {
      std::cout << "Error writing data for ignored cells!" << std::endl;
      return false;
    }
  }

   
  // add data to undirected bonds table and generate map: bond pointer -> dbid
  std::map<DirectedBond*,unsigned long> directedBondPointerToDbid;
  std::map<DirectedBond*,unsigned long> directedBondPointerToUbid;
  std::map<DirectedBond*,unsigned long> newConjBondDbids;
  std::map<DirectedBond*,DirectedBond*> newConjBondLeftOfConjBondAsSeenFromVoidCell;
  for(TissueState::BondConstIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
    DirectedBond *b = bond(it);
    ++lastDbid;
    directedBondPointerToDbid[b] = lastDbid;
    if(!b->conjBond) {
      ++lastDbid;
      newConjBondDbids[b] = lastDbid;
      
      // conj bond of bond left of conj bond seen from void cell
      Vertex *v = b->rightVertex;
      unsigned int i;
      for(i=0; i<v->bonds.size(); ++i) {
        if(v->bonds[i]==b) break;
      }
      if(i==v->bonds.size()) {
        std::cout << "TissueState::exportToDbTables: bond not found within rightVertex!" << std::endl;
        throw std::exception();
      }
      DirectedBond *oneBondCwAtVertex = v->bonds[ (i+v->bonds.size()-1)%v->bonds.size() ];
      
      Cell *c = oneBondCwAtVertex->cell;
      for(i=0; i<c->bonds.size(); ++i) {
        if(c->bonds[i]==oneBondCwAtVertex) break;
      }
      if(i==c->bonds.size()) {
        std::cout << "TissueState::exportToDbTables: bond not found within cell!" << std::endl;
        throw std::exception();
      }
      DirectedBond *oneBondCwAtCell = c->bonds[ (i+c->bonds.size()-1)%c->bonds.size() ];
      
      newConjBondLeftOfConjBondAsSeenFromVoidCell[b] = oneBondCwAtCell;
    }
    if((!b->conjBond) || (directedBondPointerToUbid.count(b->conjBond)==0)) {
      ++lastUbid;
      directedBondPointerToUbid[b] = lastUbid;
      undirectedBondsFile << _frameNumber << LogFile::DataSeparator << lastUbid << LogFile::DataSeparator << b->length << '\n';
      if(undirectedBondsFile.bad()) {
        std::cout << "Error writing undirectedBond data!" << std::endl;
        return false;
      }     
    } else {
      directedBondPointerToUbid[b] = directedBondPointerToUbid.at(b->conjBond);
    }
  }
  
  // add data to directed bonds table
  for(TissueState::BondConstIterator it=beginBondIterator(); it!=endBondIterator(); ++it) {
    DirectedBond *b = bond(it);
    if(b->conjBond) {
      directedBondsFile << _frameNumber << LogFile::DataSeparator << directedBondPointerToDbid.at(b) << LogFile::DataSeparator << directedBondPointerToDbid.at(b->conjBond) << LogFile::DataSeparator << directedBondPointerToUbid.at(b) << LogFile::DataSeparator << b->cell->id << LogFile::DataSeparator << vertexPointerToVid[b->rightVertex] << LogFile::DataSeparator << directedBondPointerToDbid.at(leftBondSeenFromCellMap.at(b)) << '\n';
      if(directedBondsFile.bad()) {
        std::cout << "Error writing directedBond data!" << std::endl;
        return false;
      }     
    } else {
      // add bond
      directedBondsFile << _frameNumber << LogFile::DataSeparator << directedBondPointerToDbid.at(b) << LogFile::DataSeparator << newConjBondDbids.at(b) << LogFile::DataSeparator << directedBondPointerToUbid.at(b) << LogFile::DataSeparator << b->cell->id << LogFile::DataSeparator << vertexPointerToVid[b->rightVertex] << LogFile::DataSeparator << directedBondPointerToDbid.at(leftBondSeenFromCellMap.at(b)) << '\n';
      if(directedBondsFile.bad()) {
        std::cout << "Error writing directedBond data!" << std::endl;
        return false;
      }
      // add new conj bond
      DirectedBond *conjBondOfLeftBondAsSeenFromVoidCell = newConjBondLeftOfConjBondAsSeenFromVoidCell.at(b);
      if(newConjBondDbids.count(conjBondOfLeftBondAsSeenFromVoidCell)==0) {
        std::cout << "TissueState::exportToDbTables: Problem with margin bonds!" << std::endl;
        throw std::exception();
      }
      directedBondsFile << _frameNumber << LogFile::DataSeparator << newConjBondDbids.at(b) << LogFile::DataSeparator << directedBondPointerToDbid.at(b) << LogFile::DataSeparator << directedBondPointerToUbid.at(b) << LogFile::DataSeparator << Cell::VoidCellId << LogFile::DataSeparator << vertexPointerToVid[b->leftVertex] << LogFile::DataSeparator << newConjBondDbids.at(conjBondOfLeftBondAsSeenFromVoidCell) << '\n';
      if(directedBondsFile.bad()) {
        std::cout << "Error writing directedBond data!" << std::endl;
        return false;
      }     
    }
  }
  
  return true;
}
// Returns the value of the unit vector between atoms i and j
// in the cart direction (cart=0=x, cart=1=y, cart=2=z)
double Molecule::calc_unit(int i, int j, int cart)
{
  return -(geom[i][cart] - geom[j][cart]) / bond(i,j);
}
Exemple #28
0
chain::chain(int N, vector<chain>* Chains,mt19937 *engine ,  list<pair<int,int>> ***Zellen)
{
	engineX=engine;

    this->Zellen=Zellen;

	uniform_real_distribution<> distribution(0, 1);
	auto rnd = bind(distribution, ref(*engineX));

	uniform_real_distribution<> PIdistribution(0, PI);
	auto rndPI = bind(PIdistribution, ref(*engineX));

	uniform_real_distribution<> NEGdistribution(-1, 1);
	auto rndWAY = bind(NEGdistribution, ref(*engineX));


//	cout << "Konstruktor Chain" << endl;
	this->Chains=Chains;
//	cout << "Pushe in Chains" << endl;
//	Chains->push_back(*this);
	this->N=N;
	vektor<double> x;
	x=vektor<double>(rnd()*XMAX,rnd()*YMAX,rnd()*ZMAX);
//	x=vektor<double>(.5*XMAX,.5*YMAX,.5*ZMAX);
//	if(k==0) x=vektor<double>(.5*XMAX+1.5*x0,.5*YMAX+x0/2+.1,.5*ZMAX-1.*x0);
//	else x=vektor<double>(.5*XMAX+x0,.5*YMAX-x0/2,.5*ZMAX-.5*x0);
//	cout << "..." << endl;
	Beads.push_back(x);

    vektor<double> ex;
//    int xtimes=0;
//    int ytimes=0;
//    int ztimes=0;
	for(int i=1;i<N;i++)
		{
//			cout << "Bead " << i << endl;
			double phi=2*rndPI();
			double theta=acos(1-2*rnd());
			ex=vektor<double>(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));
//			ex=vektor<double>(sin(phi),cos(phi),1);
//			if(k==0) ex=vektor<double>(-1,0,0);
//			else ex=vektor<double>(0,0,-1);
//			ex=vektor<double>(1,0,0);
//			if(i<N/4) ex=vektor<double>(-1,0,0);
//			if(i==N/4) ex=vektor<double>(0,-1,0);
//			if(i>N/4 && i< N/2) ex=vektor<double>(1,0,1);
//			if(i>=N/2 && i<3*N/4) ex=vektor<double>(0,0,-1);
//			if(i==3*N/4 || i==3*N/4+1) ex=vektor<double>(0,1,0);
//			if(i>3*N/4+1) ex=vektor<double>(0,0,1);

			ex=ex/ex.Betrag()*x0;



			//vektor<double> x=Beads.at(i-1).ort-ex;
			Beads.push_back(bead(Beads.at(i-1).ort));
//			vektor<double> newOrt=Beads.at(i-1).ort.add(ex);
//			if (newOrt.x>XMAX) xtimes++;
//			else if(newOrt.x<0) xtimes--;
//			if (newOrt.y>YMAX) ytimes++;
//			else if(newOrt.y<0) ytimes--;
//			if (newOrt.x>XMAX) xtimes++;
//			else if(newOrt.x<0) xtimes--;
			Beads.at(i).verschiebe(ex);
			Beads.at(i).xtimes+=Beads.at(i-1).xtimes;
			Beads.at(i).ytimes+=Beads.at(i-1).ytimes;
			Beads.at(i).ztimes+=Beads.at(i-1).ztimes;
		}

    for(int i=0;i<N-1;i++)
    {
        Bonds.push_back(bond(&Beads.at(i),&Beads.at(i+1)));
        Zellen[int(Bonds.at(i).Schwerpunkt.x/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.y/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.z/(Zellgroesse))].push_back(make_pair(Chains->size(),i));
        Bonds.at(i).self=Zellen[int(Bonds.at(i).Schwerpunkt.x/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.y/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.z/(Zellgroesse))].end();
        Bonds.at(i).self--;
//        cout << "Füge Schwerpunkt";
//        Bonds.at(i).Schwerpunkt.Ausgabe();
//        cout << "in Zelle" << int(Bonds.at(i).Schwerpunkt.x)/(Zellgroesse) << int(Bonds.at(i).Schwerpunkt.y)/(Zellgroesse) <<int(Bonds.at(i).Schwerpunkt.z)/(Zellgroesse) << "ein" << endl;
    }
//    cout << "maxSize=" <<  midBead.max_size() << endl;




}
Exemple #29
0
chain::chain(int N, vector<chain>* Chains,mt19937 *engine,list<pair<int,int>> ***Zellen, double * xVal, double * yVal, double * zVal,int *xTimes,int *yTimes,int *zTimes)
{
	engineX=engine;

    this->Zellen=Zellen;

	uniform_real_distribution<> distribution(0, 1);
	auto rnd = bind(distribution, ref(*engineX));

	uniform_real_distribution<> PIdistribution(0, PI);
	auto rndPI = bind(PIdistribution, ref(*engineX));

	uniform_real_distribution<> NEGdistribution(-1, 1);
	auto rndWAY = bind(NEGdistribution, ref(*engineX));

	uniform_int_distribution<> INTdistribution(0, N-1);
	auto INTrnd = bind(INTdistribution, ref(*engineX));
//	cout << "Konstruktor Chain" << endl;
	this->Chains=Chains;
//	cout << "Pushe in Chains" << endl;
//	Chains->push_back(*this);
	this->N=N;
	vektor<double> x;
//	x=vektor<double>(rnd()*XMAX,rnd()*YMAX,rnd()*ZMAX);
//	x=vektor<double>(.5*XMAX,.5*YMAX,.5*ZMAX);
//	if(k==0) x=vektor<double>(.5*XMAX+1.5*x0,.5*YMAX+x0/2+.1,.5*ZMAX-1.*x0);
//	else x=vektor<double>(.5*XMAX+x0,.5*YMAX-x0/2,.5*ZMAX-.5*x0);
//	cout << "..." << endl;
//	Beads.push_back(x);

//    vektor<double> ex;

	for(int i=0;i<N;i++)
		{
//			cout << "Bead " << i << endl;
//			double phi=2*rndPI();
//			double theta=acos(1-2*rnd());
//			ex=vektor<double>(sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta));
//			ex=vektor<double>(sin(phi),cos(phi),1);
//			if(k==0) ex=vektor<double>(-1,0,0);
//			else ex=vektor<double>(0,0,-1);
//			ex=vektor<double>(1,0,0);
//			if(i<N/4) ex=vektor<double>(-1,0,0);
//			if(i==N/4) ex=vektor<double>(0,-1,0);
//			if(i>N/4 && i< N/2) ex=vektor<double>(1,0,1);
//			if(i>=N/2 && i<3*N/4) ex=vektor<double>(0,0,-1);
//			if(i==3*N/4 || i==3*N/4+1) ex=vektor<double>(0,1,0);
//			if(i>3*N/4+1) ex=vektor<double>(0,0,1);
//			ex=ex/ex.Betrag()*x0;
			//vektor<double> x=Beads.at(i-1).ort-ex;
			Beads.push_back(bead(xVal[i],yVal[i],zVal[i],xTimes[i],yTimes[i],zTimes[i]));
//			Beads.at(i).verschiebe(ex);
		}

    for(int i=0;i<N-1;i++)
    {
        Bonds.push_back(bond(&Beads.at(i),&Beads.at(i+1)));
        Zellen[int(Bonds.at(i).Schwerpunkt.x/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.y/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.z/(Zellgroesse))].push_back(make_pair(Chains->size(),i));
        Bonds.at(i).self=Zellen[int(Bonds.at(i).Schwerpunkt.x/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.y/(Zellgroesse))][int(Bonds.at(i).Schwerpunkt.z/(Zellgroesse))].end();
        Bonds.at(i).self--;
//        cout << "Füge Schwerpunkt";
//        Bonds.at(i).Schwerpunkt.Ausgabe();
//        cout << "in Zelle" << int(Bonds.at(i).Schwerpunkt.x)/(Zellgroesse) << int(Bonds.at(i).Schwerpunkt.y)/(Zellgroesse) <<int(Bonds.at(i).Schwerpunkt.z)/(Zellgroesse) << "ein" << endl;
    }




}
Exemple #30
0
  Bond* Molecule::addBond()
  {
    boost::shared_ptr<Bond> bond(new Bond(this));
//    boost::add_edge(bond->bond, d_graph);
  }