// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void polyDelListOfAtoms::findMolsToDel() { label initialSize = molCloud_.size(); label deletedMols = 0; Info << nl << "Deleting the following molecules... " << nl << endl; DynamicList<vector> positions; DynamicList<scalar> rMinCollect; forAll(molPoints_, i) { DynamicList<polyMolecule*> molsToDel; IDLList<polyMolecule>::iterator mol(molCloud_.begin()); scalar rMin = GREAT; for ( mol = molCloud_.begin(); mol != molCloud_.end(); ++mol ) { if(findIndex(molIds_, mol().id()) != -1) { vector rT = molPoints_[i]; scalar magRIJ = mag(rT-mol().position()); if(magRIJ < rMin) { molsToDel.clear(); rMin = magRIJ; polyMolecule* molI = &mol(); molsToDel.append(molI); } } } forAll(molsToDel, m) { positions.append(molsToDel[m]->position()); rMinCollect.append(rMin); Info << molsToDel[m]->position() << endl; deletedMols++; deleteMolFromMoleculeCloud(*molsToDel[m]); }
void Foam::moleculeCloud::setSiteSizesAndPositions() { iterator mol(this->begin()); for (mol = this->begin(); mol != this->end(); ++mol) { const molecule::constantProperties& cP = constProps(mol().id()); mol().setSiteSizes(cP.nSites()); mol().setSitePositions(cP); } }
void tail::controlBeforeMove() { getPosition(); t_ += deltaTMD_; if(t_ < relaxationTime_) { Info << "tail: relaxation" << endl; IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(mol().trackingNumber() == trackingNumber_) { mol().a() = vector::zero; mol().v() = deltaR_/deltaTMD_; } } } if(t_ > relaxationTime_) { tI_ += deltaT_; Info << "tail: control, t = " << tI_ << endl; IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { { if(mol().trackingNumber() == trackingNumber_) { scalar xNew = -a_*cos(tI_+(constant::mathematical::pi/2)) + centre_.x(); scalar yNew = b_*sin(tI_+(constant::mathematical::pi/2)) + centre_.y(); Info << "xNew = " << xNew << ", yNew = " << yNew << endl; vector rNew = vector(xNew, yNew, centre_.z()); vector deltaR = rNew - mol().position(); mol().a() = vector::zero; mol().v() = deltaR/deltaTMD_; } } } } }
int main(int argc, char **argv) { std::string file_root = getenv("RDBASE"); file_root += "/Docs/Book"; std::string mol_file = file_root + "/data/chiral.mol"; RDKit::ROMOL_SPTR mol(RDKit::MolFileToMol(mol_file)); std::cout << RDKit::MolToSmiles(*mol, true) << std::endl; // 2nd parameter doIsomericSmiles defaults to true std::cout << RDKit::MolToSmiles(*mol, false) << std::endl; RDKit::ROMOL_SPTR mol1(RDKit::SmilesToMol("C1=CC=CN=C1")); std::cout << RDKit::MolToSmiles(*mol1) << std::endl; RDKit::ROMOL_SPTR mol2(RDKit::SmilesToMol("c1cccnc1")); std::cout << RDKit::MolToSmiles(*mol2) << std::endl; RDKit::ROMOL_SPTR mol3(RDKit::SmilesToMol("n1ccccc1")); std::cout << RDKit::MolToSmiles(*mol3) << std::endl; RDKit::RWMOL_SPTR mol4(new RDKit::RWMol(*mol)); RDKit::MolOps::Kekulize(*mol4); std::cout << RDKit::MolToSmiles(*mol4) << std::endl; mol1.reset(RDKit::SmilesToMol("C1CCC1")); std::cout << RDKit::MolToMolBlock(*mol1) << std::endl; mol1->setProp("_Name", "cyclobutane"); std::cout << RDKit::MolToMolBlock(*mol1) << std::endl; }
QString MOPACInputDialog::generateInputDeck() { // Generate an input deck based on the settings of the dialog QString buffer; QTextStream mol(&buffer); mol << " AUX LARGE "; mol << "CHARGE=" << m_charge << ' '; switch (m_multiplicity) { case 2: mol << "DOUBLET "; break; case 3: mol << "TRIPLET "; break; case 4: mol << "QUARTET "; break; case 5: mol << "QUINTET "; break; case 1: default: mol << "SINGLET "; } mol << getCalculationType(m_calculationType) << ' '; mol << getTheoryType(m_theoryType) << '\n'; mol << m_title << "\n\n"; // Now to output the actual molecular coordinates QString optimizationFlag; if (m_calculationType == SP) optimizationFlag = " 0 "; // we could actually obey constraints easily else optimizationFlag = " 1 "; // Cartesian coordinates if (m_molecule && m_coordType == CARTESIAN) { QList<Atom *> atoms = m_molecule->atoms(); foreach (Atom *atom, atoms) { mol << qSetFieldWidth(4) << right << QString(OpenBabel::etab.GetSymbol(atom->atomicNumber())) << qSetFieldWidth(15) << qSetRealNumberPrecision(5) << forcepoint << fixed << right << atom->pos()->x() << optimizationFlag << atom->pos()->y() << optimizationFlag << atom->pos()->z() << optimizationFlag << qSetFieldWidth(0) << '\n'; }
void tail::getPosition() { rI_ = vector::zero; IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(mol().trackingNumber() == trackingNumber_) { rI_ = mol().position(); } } //- parallel processing if(Pstream::parRun()) { reduce(rI_, sumOp<vector>()); } Info << "mol position = " << rI_ << endl; }
void Foam::moleculeCloud::calculateTetherForce() { iterator mol(this->begin()); vector rIT; scalar rITMag; vector fIT; for (mol = this->begin(); mol != this->end(); ++mol) { if (mol().tethered()) { rIT = mol().position() - mol().tetherPosition(); rITMag = mag(rIT); fIT = (rIT/rITMag) * tetherPotentials_.force ( mol().id(), rITMag ); mol().A() += fIT/(mol().mass()); mol().potentialEnergy() += tetherPotentials_.energy ( mol().id(), rITMag ); mol().rf() += rIT*fIT; } } }
void testFuncTerm() { FuncTerm ft; ft.setExpr( "x0 + x1 * t" ); double args[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // First check that it doesn't die even if we forget to set up anything. double ans = ft( args, 2.0 ); vector< unsigned int > mol( 2, 0 ); mol[0] = 2; mol[1] = 0; ft.setReactantIndex( mol ); ans = ft( args, 10.0 ); assert( doubleEq( ans, 13.0 ) ); mol[0] = 0; mol[1] = 9; ft.setReactantIndex( mol ); ans = ft( args, 2.0 ); assert( doubleEq( ans, 21.0 ) ); cout << "." << flush; }
int main(int argc, char** argv) { double T(1); double L(1.44e-6); unsigned N(100); double R(2.5e-9); double D(1e-12); if (argc == 6) { T = std::stod(argv[1]); L = std::stod(argv[2]); N = std::stoi(argv[3]); R = std::stod(argv[4]); D = std::stod(argv[5]); } const double dt(2*R*R/3/D); const unsigned nSim(T/dt); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> unidist(0, L); std::normal_distribution<> normdist(0, pow(2*D*dt,0.5)); std::vector<Coordinate> mols; for (unsigned i(0); i < N; ++i) { Coordinate mol(unidist(gen), unidist(gen), unidist(gen)); mols.push_back(mol); } auto start = std::chrono::high_resolution_clock::now(); for (unsigned n(0); n < nSim; ++n) { for (unsigned j(0); j < N; ++j) { mols[j].x = mod(mols[j].x+normdist(gen), L); mols[j].y = mod(mols[j].y+normdist(gen), L); mols[j].z = mod(mols[j].z+normdist(gen), L); } } auto finish = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = finish - start; std::cout << "elapsed:" << elapsed.count() << " s" << std::endl; }
void polyOutputProperties::calculateField() { nAvTimeSteps_ += 1.0; vector singleStepTotalLinearMomentum(vector::zero); vector singleStepTotalAngularMomentum(vector::zero); scalar singleStepMaxVelocityMag = 0.0; scalar singleStepTotalMass = 0.0; scalar singleStepTotalLinearKE = 0.0; scalar singleStepTotalAngularKE = 0.0; scalar singleStepTotalPE = 0.0; scalar singleStepTotalrDotf = 0.0; label singleStepNMols = molCloud_.size(); label singleStepDOFs = 0; { IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for ( mol = molCloud_.begin(); mol != molCloud_.end(); ++mol ) { label molId = mol().id(); scalar molMass(molCloud_.cP().mass(molId)); singleStepTotalMass += molMass; } for ( mol = molCloud_.begin(); mol != molCloud_.end(); ++mol ) { label molId = mol().id(); scalar molMass(molCloud_.cP().mass(molId)); const vector& molV(mol().v()); vector molPiGlobal = vector::zero; vector molOmega = vector::zero; const diagTensor& molMoI(molCloud_.cP().momentOfInertia(molId)); if(!molCloud_.cP().pointMolecule(molId)) { molOmega = inv(molMoI) & mol().pi(); molPiGlobal = mol().Q() & mol().pi(); } singleStepTotalLinearMomentum += molV * molMass; singleStepTotalAngularMomentum += molPiGlobal; if(mag(molV) > singleStepMaxVelocityMag) { singleStepMaxVelocityMag = mag(molV); } singleStepTotalLinearKE += 0.5*molMass*magSqr(molV); singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega); singleStepTotalPE += mol().potentialEnergy(); singleStepTotalrDotf += tr(mol().rf()); singleStepDOFs += molCloud_.cP().degreesOfFreedom(molId); } } if (Pstream::parRun()) { reduce(singleStepTotalLinearMomentum, sumOp<vector>()); reduce(singleStepTotalAngularMomentum, sumOp<vector>()); reduce(singleStepMaxVelocityMag, maxOp<scalar>()); reduce(singleStepTotalMass, sumOp<scalar>()); reduce(singleStepTotalLinearKE, sumOp<scalar>()); reduce(singleStepTotalAngularKE, sumOp<scalar>()); reduce(singleStepTotalPE, sumOp<scalar>()); reduce(singleStepTotalrDotf, sumOp<scalar>()); reduce(singleStepNMols, sumOp<label>()); reduce(singleStepDOFs, sumOp<label>()); } if (singleStepNMols) { Info<< "Number of molecules in system = " << singleStepNMols << nl << "Overall number density = " << singleStepNMols/meshVolume_ << nl << "Overall mass density = " << singleStepTotalMass/meshVolume_ << nl << "Average linear momentum per molecule = " << singleStepTotalLinearMomentum/singleStepNMols << ' ' << mag(singleStepTotalLinearMomentum)/singleStepNMols << nl << "Average angular momentum per molecule = " << singleStepTotalAngularMomentum << ' ' << mag(singleStepTotalAngularMomentum)/singleStepNMols << nl << "Maximum |velocity| = " << singleStepMaxVelocityMag << nl << "Average linear KE per molecule = " << singleStepTotalLinearKE/singleStepNMols << nl << "Average angular KE per molecule = " << singleStepTotalAngularKE/singleStepNMols << nl << "Average PE per molecule = " << singleStepTotalPE/singleStepNMols << nl << "Average TE per molecule = " << ( singleStepTotalLinearKE + singleStepTotalAngularKE + singleStepTotalPE ) /singleStepNMols << endl; } else { Info<< "No molecules in system" << endl; } accumulatedTotalLinearMomentum_ += singleStepTotalLinearMomentum; accumulatedTotalMass_ += singleStepTotalMass; accumulatedTotalLinearKE_ += singleStepTotalLinearKE; accumulatedTotalAngularKE_ += singleStepTotalAngularKE; accumulatedTotalPE_ += singleStepTotalPE; accumulatedTotalrDotfSum_ += singleStepTotalrDotf; accumulatedNMols_ += singleStepNMols; accumulatedDOFs_ += singleStepDOFs; }
void polyForceTwoShear::controlAfterForces() { scalar molsLiquid = 0.0; scalar molsGas = 0.0; // measurements of instantaneous density { IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(bb_liquid_A_.contains(mol().position()) || bb_liquid_B_.contains(mol().position())) { if(findIndex(molIds_, mol().id()) != -1) { molsLiquid += 1.0; } } if(bb_gas_A_.contains(mol().position()) || bb_gas_B_.contains(mol().position())) { if(findIndex(molIds_, mol().id()) != -1) { molsGas += 1.0; } } } // parallel processing if(Pstream::parRun()) { reduce(molsLiquid, sumOp<scalar>()); reduce(molsGas, sumOp<scalar>()); } } forceMagGas_ = forceMagLiquid_*molsLiquid/molsGas; Info << "polyForceTwoShear: control - force liquid = " << forceMagLiquid_ << " , force gas = " << forceMagGas_ << endl; IDLList<polyMolecule>::iterator mol(molCloud_.begin()); vector totalForceLiquid = vector::zero; vector totalForceGas = vector::zero; for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(bb_liquid_A_.contains(mol().position()) || bb_liquid_B_.contains(mol().position())) { if(findIndex(molIds_, mol().id()) != -1) { const scalar& massI = molCloud_.cP().mass(mol().id()); vector force = forceMagLiquid_; mol().a() += force/massI; totalForceLiquid += force; } } if(bb_gas_A_.contains(mol().position()) || bb_gas_B_.contains(mol().position())) { if(findIndex(molIds_, mol().id()) != -1) { const scalar& massI = molCloud_.cP().mass(mol().id()); vector force = -forceMagGas_; mol().a() += force/massI; totalForceGas += force; } } } if(Pstream::parRun()) { reduce(totalForceLiquid, sumOp<vector>()); reduce(totalForceGas, sumOp<vector>()); } Info << "polyForceTwoShear: Conservation- total force liquid = " << totalForceLiquid << " , total force gas = " << totalForceGas << " , diff = " << totalForceLiquid + totalForceGas << endl; }
void polyVelocityBounded::controlBeforeVelocityI() { scalar mass = 0.0; scalar mols = 0.0; vector mom = vector::zero; { IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(findIndex(molIds_, mol().id()) != -1) { if(bb_.contains(mol().position())) { const scalar& massI = molCloud_.cP().mass(mol().id()); mass += massI; mom += mol().v()*massI; mols += 1.0; } } } } if (Pstream::parRun()) { reduce(mols, sumOp<scalar>()); reduce(mass, sumOp<scalar>()); reduce(mom, sumOp<vector>()); } vector velocityMeasured = vector::zero; if(mass > 0) { velocityMeasured = mom/mass; } vector deltaU = (velocity_ - velocityMeasured)*lambda_; accumulatedTime_ += deltaT_; if((accumulatedTime_ >= startTime_) && (accumulatedTime_ <= endTime_)) { IDLList<polyMolecule>::iterator mol(molCloud_.begin()); for (mol = molCloud_.begin(); mol != molCloud_.end(); ++mol) { if(findIndex(molIds_, mol().id()) != -1) { if(bb_.contains(mol().position())) { if(componentControl_) { if(X_) { mol().v().x() += deltaU.x(); } if(Y_) { mol().v().y() += deltaU.y(); } if(Z_) { mol().v().z() += deltaU.z(); } } else { mol().v() += deltaU; } } } } Info << "polyVelocityBounded - controlling: " << " target velocity = " << velocity_ << ", vel Meas = " << velocityMeasured << ", DeltaU = " << deltaU << endl; } }
/** @see molecule.h */ int Molecule_new(int numAtoms, int *Z, double *r3, double *Q) { Molecule mol(numAtoms, Z, r3, Q); molecules.push_back(mol); return (molecules.size() - 1 + OFFSET); }
int main() { /** Step 1: Read the Coordinate Data * */ FILE *xyzfile; xyzfile = fopen("h2o_geom.txt", "r"); int natom; fscanf(xyzfile, "%d", &natom); Molecule mol(natom, 0); for (int i = 0; i < natom; i++) fscanf(xyzfile, "%lf %lf %lf %lf", &mol.zvals[i], &mol.geom[i][0], &mol.geom[i][1], &mol.geom[i][2]); fclose(xyzfile); /** Step 2: Read the Cartesian Hessian Data * */ FILE *hessfile; hessfile = fopen("h2o_hessian.txt", "r"); int hessatom; fscanf(hessfile, "%d", &hessatom); if (fabs(natom-hessatom) > 0) { printf("The number of atoms doesn't match.\n"); return -1; } double **H = new double* [3*natom]; for (int i = 0; i < 3*natom; i++) H[i] = new double[3*natom]; for (int i = 0; i < 3*natom; i++) for (int j = 0; j < natom; j++) fscanf(hessfile, "%lf %lf %lf", &H[i][3*j], &H[i][3*j+1], &H[i][3*j+2]); fclose(hessfile); printf("Hessian:\n"); print_mat(H, 3*natom, 3*natom); printf("\n"); /** Step 3: Mass-Weight the Hessian Matrix * Divide each element of the Hessian matrix by the product of square roots of the masses of the atoms associated with the given coordinates: * \vect{F}_{M}^{ij} = \frac{F_{ij}}{\sqrt{m_{i}m_{j}}} */ double **Hmw = new double* [3*natom]; for (int i = 0; i < 3*natom; i++) Hmw[i] = new double[3*natom]; double mi, mj, mimj; for (int i = 0; i < natom; i++) { for (int j = 0; j < natom; j++) { mi = masses[(int)mol.zvals[i]]; mj = masses[(int)mol.zvals[j]]; mimj = sqrt(mi*mj); Hmw[i*natom+0][j*natom+0] = H[i*natom+0][j*natom+0]/mimj; Hmw[i*natom+0][j*natom+1] = H[i*natom+0][j*natom+1]/mimj; Hmw[i*natom+0][j*natom+2] = H[i*natom+0][j*natom+2]/mimj; Hmw[i*natom+1][j*natom+0] = H[i*natom+1][j*natom+0]/mimj; Hmw[i*natom+1][j*natom+1] = H[i*natom+1][j*natom+1]/mimj; Hmw[i*natom+1][j*natom+2] = H[i*natom+1][j*natom+2]/mimj; Hmw[i*natom+2][j*natom+0] = H[i*natom+2][j*natom+0]/mimj; Hmw[i*natom+2][j*natom+1] = H[i*natom+2][j*natom+1]/mimj; Hmw[i*natom+2][j*natom+2] = H[i*natom+2][j*natom+2]/mimj; } } printf("Mass-weighted Hessian:\n"); print_mat(Hmw, 3*natom, 3*natom); printf("\n"); /** Step 4: Diagonalize the Mass-Weighted Hessian Matrix * Compute the eigenvalues of the mass-weighted Hessian: * \vect{F}^{M}\vect{L} = \vect{L}\vect{\Lambda} */ double *evals = new double[3*natom]; for (int i = 0; i < 3*natom; i++) evals[i] = 0.0; double **evecs = new double* [3*natom]; for (int i = 0; i < 3*natom; i++) evecs[i] = new double[3*natom]; diag(3*natom, 3*natom, Hmw, evals, false, evecs, 1e-19); for (int i = 0; i < 3*natom; i++) delete[] evecs[i]; delete[] evecs; printf("Mass-weighted Hessian eigenvalues:\n"); for (int i = 0; i < 3*natom; i++) printf("%12.10f\n", evals[i]); printf("\n"); /** Step 5: Compute the Harmonic Vibrational Frequencies * The vibrational frequencies are proportional to the square root of the eigenvalues of the mass-weighted Hessian: * \omega_{i} = \textrm{constant} \times \sqrt{\lambda_{i}} */ printf("Harmonic vibrational frequences [cm]^-1:\n"); for (int i = 0; i < 3*natom; i++) printf("%10.4f\n", sqrt(evals[i])*vib_constant); printf("\n"); /// Clean up after ourselves... for (int i = 0; i < 3*natom; i++) { delete[] H[i]; delete[] Hmw[i]; } delete[] H; delete[] Hmw; delete[] evals; return 0; }