Example #1
0
File: f.cpp Project: mayah/ICPC
Molecule addMolecules(const Molecule &molecule1, const Molecule &molecule2) {
	Molecule output = molecule1;
	for (Molecule::const_iterator it2 = molecule2.begin(); it2 != molecule2.end(); it2++) {
		Molecule::iterator ito = output.find(it2->first);
		if (ito != output.end()) {
			ito->second += it2->second;
		} else {
			output[it2->first] = it2->second;
		}
	}
	return output;
}
Example #2
0
File: f.cpp Project: mayah/ICPC
void printMolecule(const Molecule &m) {
	cout << "[";
	for (Molecule::const_iterator it = m.begin(); it != m.end(); it++) {
		cout << "(" << it->first << ", " << it->second << ") ";
	}
	cout << "]";
}
Example #3
0
File: f.cpp Project: mayah/ICPC
Molecule multiplyMolecule(const Molecule &molecule, int multiplier) {
	Molecule output;
	for (Molecule::const_iterator it = molecule.begin(); it != molecule.end(); it++) {
		output[it->first] = it->second * multiplier;
	}
	return output;
}
void MoleculeGroup::AddMolecule(const int molecule_id, const Molecule& molecule,
                            const arma::rowvec& position,
                            const arma::rowvec& velocity)
{
    // TODO(Zak): Allow for polyatomic molecules by randomly
    // orienting around center of mass position.
    // This assert is a placeholder until then.
    assert (molecule.num_atoms() == 1);
    molecule_names_.push_back(molecule.name());
    molecular_index_to_mass_.push_back(molecule.mass());
    molecular_index_to_molecule_.push_back(molecule_id);
    for (std::vector<Atom>::const_iterator i_atom = molecule.begin();
         i_atom != molecule.end(); ++i_atom) {
      AddAtom(*i_atom, molecule_id, position, velocity);
    }
    num_molecules_++;
    com_positions_.insert_rows(com_positions_.n_rows, position);
    com_velocities_.insert_rows(com_velocities_.n_rows, velocity);
}
Example #5
0
// Makes a repeating slab out of a single unit cell by creating copies and shifting
Mol_ptr_vec UnitCellToSlab (GridParams& params) {

  std::vector<Molecule *> mols;
  Molecule * uc = params.unitCell;

  VecR yshift, xshift, zshift;

  yshift.Zero();
  for (int i = 0; i < params.y; i++) {
    zshift.Zero();

    for (int j = 0; j < params.x; j++) {
      xshift.Zero();
      if (!(j % 2))
		xshift += params.x_shift * 0.5;

      for (int k = 0; k < params.z; k++) {

	// make a copy of the unitcell
	Molecule * copy = new Molecule();
	copy->Name(params.name);
	// make copies of all the atoms in the unitcell
	for (Atom_it atom_i = uc->begin(); atom_i != uc->end(); atom_i++) {
	//for (int atom = 0; atom < uc->size(); atom++) {
	  Atom * pa = new Atom (*(*atom_i));
	  copy->AddAtom(pa);
	}

	// shift the new copy to the next lattice point
	copy->Shift(yshift + xshift + zshift);
	mols.push_back(copy);

	xshift += params.x_shift;
      } 

      zshift += params.z_shift;
    } 
    yshift += params.y_shift;
  }

  return mols;
}
Example #6
0
double Molecule::MinDistance (Molecule& mol) {
    // go through the atoms on each molecule and calculate the distance between them, then return the minimum
    bool first = true;
    double min = 0.0;

    for (Atom_it it = this->begin(); it != this->end(); it++) {
        for (Atom_it jt = mol.begin(); jt != mol.end(); jt++) {

            double temp = ((*it)->Position() - (*jt)->Position()).Magnitude();
            //printf ("%f\n", temp);
            if (first) {
                first = false;
                min = temp;
            }

            if (temp < min) {
                min = temp;
            }
        }
    }

    return (min);
}