Ignore:
Timestamp:
Jan 14, 2015, 9:03:24 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
cad383
Parents:
601ef8
git-author:
Frederik Heber <heber@…> (01/14/15 20:31:24)
git-committer:
Frederik Heber <heber@…> (01/14/15 21:03:24)
Message:

FIX: Changed SuspendInMoleculeAction to catch segfault when rho=1 was given.

  • however, the action is still not tested to work.
  • TESTFIX: suspend-in-water gets parameter density via "density" not via "suspend-in-water", set desired density to faulting 1 for the moment.
  • TESTFIX: added water molecule to test.conf, to have at least two molecules.
Location:
src/Actions/FillAction
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FillAction/SuspendInMoleculeAction.cpp

    r601ef8 r2440ce  
    129129  filler->CenterEdge();
    130130
     131  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     132  if (molecules.size() < 2) {
     133    STATUS("There must be at least two molecules: filler and to be suspended.");
     134    return Action::failure;
     135  }
     136
    131137  /// first we need to calculate some volumes and masses
    132   std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
    133138  double totalmass = 0.;
    134139  const bool IsAngstroem = true;
     
    139144      iter != molecules.end(); ++iter)
    140145  {
     146    // skip the filler
     147    if (*iter == filler)
     148      continue;
    141149    molecule & mol = **iter;
    142150    const double mass = calculateMass(mol);
     
    152160  LOG(1, "INFO: The average density is " << setprecision(10)
    153161      << totalmass / clustervolume << " atomicmassunit/"
    154       << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
     162      << (IsAngstroem ? " angstrom" : " atomiclength") << "^3.");
     163  if ( ((totalmass / clustervolume < 1.) && (params.density.get() > 1.))
     164      || ((totalmass / clustervolume > 1.) && (params.density.get() < 1.))) {
     165    STATUS("Desired and present molecular densities must both be either in [0,1) or in (1, inf).");
     166    return Action::failure;
     167  }
    155168
    156169  // calculate maximum solvent density
    157170  std::vector<double> fillerdiameters(NDIM, 0.);
    158   const double solventdensity =
    159       calculateMass(*filler) / calculateEnvelopeVolume(*filler, fillerdiameters);
    160 
    161   std::vector<unsigned int> counts(3, 0);
    162   Vector offset(.5,.5,.5);
     171  const double fillervolume = calculateEnvelopeVolume(*filler, fillerdiameters);
     172  const double fillermass = calculateMass(*filler);
     173  LOG(1, "INFO: The filler's mass is " << setprecision(10)
     174      << fillermass << " atomicmassunit, and it's volume is "
     175      << fillervolume << (IsAngstroem ? " angstrom" : " atomiclength") << "^3.");
     176  const double solventdensity = fillermass / fillervolume;
    163177
    164178  /// solve cubic polynomial
    165179  double cellvolume = 0.;
    166180  LOG(1, "Solving equidistant suspension in water problem ...");
    167   cellvolume = (totalmass / solventdensity
    168       - (totalmass / clustervolume)) / (params.density.get() - 1.);
     181  // s = solvent, f = filler, 0 = initial molecules/cluster
     182  // v_s = v_0 + v_f, m_s = m_0 + rho_f * v_f --> rho_s = m_s/v_s ==> v_f = (m_0 - rho_s * v_o) / (rho_s - rho_f)
     183  cellvolume = (totalmass - params.density.get() * clustervolume) / (params.density.get() - 1.) + clustervolume;
    169184  LOG(1, "Cellvolume needed for a density of " << params.density.get()
    170185      << " g/cm^3 is " << cellvolume << " angstroem^3.");
     
    173188      (GreatestDiameter[0] * GreatestDiameter[1] * GreatestDiameter[2]);
    174189  LOG(1, "Minimum volume of the convex envelope contained in a rectangular box is "
    175       << minimumvolume << "angstrom^3.");
     190      << minimumvolume << " angstrom^3.");
    176191
    177192  if (minimumvolume > cellvolume) {
     
    187202        + GreatestDiameter[1] * GreatestDiameter[2];
    188203    BoxLengths[2] = minimumvolume - cellvolume;
    189     double x0 = 0.;
    190     double x1 = 0.;
    191     double x2 = 0.;
     204    std::vector<double> x(3, 0.);
    192205    // for cubic polynomial there are either 1 or 3 unique solutions
    193     if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1)
    194       LOG(0, "RESULT: The resulting spacing is: " << x0 << " .");
    195     else {
    196       LOG(0, "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " .");
    197       std::swap(x0, x2); // sorted in ascending order
    198     }
     206    if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x[0], &x[1], &x[2]) == 1) {
     207      x[1] = x[0];
     208      x[2] = x[0];
     209    } else {
     210      std::swap(x[0], x[2]); // sorted in ascending order
     211    }
     212    LOG(0, "RESULT: The resulting spacing is: " << x << " .");
    199213
    200214    cellvolume = 1.;
    201215    for (size_t i = 0; i < NDIM; ++i) {
    202       BoxLengths[i] = x0 + GreatestDiameter[i];
     216      BoxLengths[i] = x[i] + GreatestDiameter[i];
    203217      cellvolume *= BoxLengths[i];
    204218    }
    205 
    206     // set new box dimensions
    207     LOG(0, "Translating to box with these boundaries.");
    208     {
    209       RealSpaceMatrix domain;
    210       for(size_t i =0; i<NDIM;++i)
    211         domain.at(i,i) = BoxLengths[i];
    212       World::getInstance().setDomain(domain);
    213     }
    214 //    mol->CenterInBox();
     219  }
     220
     221  // TODO: Determine counts from resulting mass correctly (hard problem due to integers)
     222  std::vector<unsigned int> counts(3, 0);
     223  const unsigned int totalcounts = round(params.density.get() * cellvolume - totalmass) / fillermass;
     224  if (totalcounts > 0) {
     225    counts[0] = ceil(BoxLengths[0]/3.1);
     226    counts[1] = ceil(BoxLengths[1]/3.1);
     227    counts[2] = ceil(BoxLengths[2]/3.1);
    215228  }
    216229
     
    231244      params.RandMoleculeDisplacement.get(),
    232245      params.DoRotate.get());
     246  Vector offset(.5,.5,.5);
    233247  filler_preparator.addCubeMesh(
    234248      counts,
  • src/Actions/FillAction/SuspendInMoleculeAction.def

    r601ef8 r2440ce  
    1717#include "Parameters/Validators/RangeValidator.hpp"
    1818#include "Parameters/Validators/STLVectorValidator.hpp"
     19#include "Parameters/Validators/Ops_Validator.hpp"
    1920#include "Parameters/Validators/Specific/BoxLengthValidator.hpp"
    2021#include "Parameters/Validators/Specific/VectorZeroOneComponentsValidator.hpp"
     
    2526#define paramtypes (double)(double)(double)(double)(bool)
    2627#define paramtokens ("density")("min-distance")("random-atom-displacement")("random-molecule-displacement")("DoRotate")
    27 #define paramdescriptions ("desired density for the total domain")("minimum distance of water molecules to present atoms")("magnitude of random atom displacement")("magnitude of random molecule displacement")("whether to rotate or not")
     28#define paramdescriptions ("desired density for the total domain, unequal 1.")("minimum distance of water molecules to present atoms")("magnitude of random atom displacement")("magnitude of random molecule displacement")("whether to rotate or not")
    2829#define paramdefaults (PARAM_DEFAULT(1.))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(0.))(PARAM_DEFAULT(0.))(PARAM_DEFAULT(false))
    2930#define paramreferences (density)(mindistance)(RandAtomDisplacement)(RandMoleculeDisplacement)(DoRotate)
    3031#define paramvalids \
    31 (RangeValidator< double >(0., std::numeric_limits<double>::max())) \
     32(RangeValidator< double >(0., 1. - std::numeric_limits<double>::epsilon()) || RangeValidator< double >(1. + std::numeric_limits<double>::epsilon(), std::numeric_limits<double>::max())) \
    3233(BoxLengthValidator()) \
    3334(BoxLengthValidator()) \
Note: See TracChangeset for help on using the changeset viewer.