Ignore:
Timestamp:
Sep 10, 2014, 7:55:12 AM (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:
36f45c
Parents:
a090e3
git-author:
Frederik Heber <heber@…> (09/02/14 15:06:31)
git-committer:
Frederik Heber <heber@…> (09/10/14 07:55:12)
Message:

Extracted filler preparing functionality from FillRegularGridAction.

File:
1 edited

Legend:

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

    ra090e3 rcae614  
    4444#include "Filling/Cluster.hpp"
    4545#include "Filling/Filler.hpp"
    46 #include "Filling/Inserter/Inserter.hpp"
    47 #include "Filling/Inserter/RandomInserter.hpp"
    48 #include "Filling/Mesh/CubeMesh.hpp"
    49 #include "Filling/Predicates/IsInsideSurface_FillPredicate.hpp"
    50 #include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
    51 #include "Filling/Predicates/Ops_FillPredicate.hpp"
    52 #include "LinkedCell/linkedcell.hpp"
    53 #include "LinkedCell/PointCloudAdaptor.hpp"
     46#include "Filling/Preparators/BoxFillerPreparator.hpp"
    5447#include "molecule.hpp"
    5548#include "MoleculeListClass.hpp"
    5649#include "Parser/FormatParserInterface.hpp"
    5750#include "Parser/FormatParserStorage.hpp"
    58 #include "Shapes/BaseShapes.hpp"
    59 #include "Tesselation/tesselation.hpp"
    60 #include "Tesselation/BoundaryLineSet.hpp"
    61 #include "Tesselation/BoundaryTriangleSet.hpp"
    62 #include "Tesselation/CandidateForTesselation.hpp"
    6351#include "World.hpp"
    6452
     
    9482  filler->CenterEdge();
    9583
    96   // check for selected atoms and create surfaces from them
    97   std::vector<atom *> atoms(World::getInstance().getSelectedAtoms());
    98   FillPredicate * surface_predicate = NULL;
    99   LinkedCell_deprecated * LC = NULL;
    100   Tesselation * TesselStruct = NULL;
     84  // prepare the filler preparator
     85  BoxFillerPreparator filler_preparator(filler);
    10186  if (params.SphereRadius.get() != 0.) {
    102     if ( atoms.size() == 0) {
     87    if (World::getInstance().beginAtomSelection() == World::getInstance().endAtomSelection()) {
    10388      STATUS("You have given a sphere radius "+toString(params.SphereRadius.get())
    10489          +" != 0, but have not select any atoms.");
    10590      return Action::failure;
    10691    }
    107     // create adaptor for the selected atoms
    108     PointCloudAdaptor< std::vector<atom *> > cloud(&atoms, std::string("Selected atoms"));
    109 
    110     // create tesselation
    111     LC = new LinkedCell_deprecated(cloud, 2.*params.SphereRadius.get());
    112     TesselStruct = new Tesselation;
    113     (*TesselStruct)(cloud, params.SphereRadius.get());
    114 
    115     // and create predicate
    116     surface_predicate = new FillPredicate( IsInsideSurface_FillPredicate( *TesselStruct, *LC ) );
    117   }
    118 
    119   // create predicate, mesh, and filler
     92    std::vector<atom*> atoms(World::getInstance().getSelectedAtoms());
     93    filler_preparator.addSurfacePredicate(
     94        params.SphereRadius.get(),
     95        atoms);
     96  }
     97  filler_preparator.addVoidPredicate(params.mindistance.get());
     98  filler_preparator.addRandomInserter(
     99      params.RandAtomDisplacement.get(),
     100      params.RandMoleculeDisplacement.get(),
     101      params.DoRotate.get());
     102  filler_preparator.addCubeMesh(
     103      params.counts.get(),
     104      params.offset.get(),
     105      World::getInstance().getDomain().getM());
     106  if (!filler_preparator()) {
     107    STATUS("Filler was not fully constructed.");
     108    return Action::failure;
     109  }
     110
     111  // use filler
     112  bool successflag = false;
    120113  FillRegularGridState *UndoState = NULL;
    121   bool successflag = false;
    122114  {
    123     FillPredicate *voidnode_predicate = new FillPredicate(
    124         IsVoidNode_FillPredicate(
    125             Sphere(zeroVec, params.mindistance.get())
    126             )
    127         );
    128     FillPredicate Andpredicate = (*voidnode_predicate);
    129     if (surface_predicate != NULL)
    130       Andpredicate = (Andpredicate) && !(*surface_predicate);
    131     Mesh *mesh = new CubeMesh(params.counts.get(), params.offset.get(), World::getInstance().getDomain().getM());
    132     Inserter *inserter = new Inserter(
    133         Inserter::impl_ptr(
    134             new RandomInserter(
    135                 params.RandAtomDisplacement.get(),
    136                 params.RandMoleculeDisplacement.get(),
    137                 params.DoRotate.get())
    138             )
    139         );
    140 
    141115    // fill
    142     {
    143       Filler *fillerFunction = new Filler(*mesh, Andpredicate, *inserter);
    144       // TODO: When molecule::getBoundingSphere() does not use a sphere anymore,
    145       // we need to check whether we rotate the molecule randomly. For this to
    146       // work we need a sphere!
    147       const Shape s = filler->getBoundingSphere(params.RandAtomDisplacement.get());
    148       ClusterInterface::Cluster_impl cluster( new Cluster(filler->getAtomIds(), s) );
    149       CopyAtoms_withBonds copyMethod;
    150       Filler::ClusterVector_t ClonedClusters;
    151       successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters);
    152       delete fillerFunction;
    153 
    154       // append each cluster's atoms to clonedatoms (however not selected ones)
    155       std::vector<const atom *> clonedatoms;
    156       std::vector<AtomicInfo> clonedatominfos;
    157       for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin();
    158           iter != ClonedClusters.end(); ++iter) {
    159         const AtomIdSet &atoms = (*iter)->getAtomIds();
    160         clonedatoms.reserve(clonedatoms.size()+atoms.size());
    161         for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter)
    162           if (!filler->containsAtom(*atomiter)) {
    163             clonedatoms.push_back( *atomiter );
    164             clonedatominfos.push_back( AtomicInfo(*(*atomiter)) );
    165           }
    166       }
    167       std::vector< BondInfo > clonedbonds;
    168       StoreBondInformationFromAtoms(clonedatoms, clonedbonds);
    169       LOG(2, "DEBUG: There are " << clonedatominfos.size() << " newly created atoms.");
    170 
    171       if (!successflag) {
    172         STATUS("Insertion failed, removing inserted clusters, translating original one back");
    173         RemoveAtomsFromAtomicInfo(clonedatominfos);
    174         clonedatoms.clear();
    175         SetAtomsFromAtomicInfo(movedatoms);
    176       } else {
    177         std::vector<Vector> MovedToVector(filler->size(), zeroVec);
    178         std::transform(filler->begin(), filler->end(), MovedToVector.begin(),
    179             boost::bind(&AtomInfo::getPosition, _1) );
    180         UndoState = new FillRegularGridState(clonedatominfos,clonedbonds,movedatoms,MovedToVector,params);
    181       }
     116    Filler *fillerFunction = filler_preparator.obtainFiller();
     117    // TODO: When molecule::getBoundingSphere() does not use a sphere anymore,
     118    // we need to check whether we rotate the molecule randomly. For this to
     119    // work we need a sphere!
     120    const Shape s = filler->getBoundingSphere(params.RandAtomDisplacement.get());
     121    ClusterInterface::Cluster_impl cluster( new Cluster(filler->getAtomIds(), s) );
     122    CopyAtoms_withBonds copyMethod;
     123    Filler::ClusterVector_t ClonedClusters;
     124    successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters);
     125    delete fillerFunction;
     126
     127    // append each cluster's atoms to clonedatoms (however not selected ones)
     128    std::vector<const atom *> clonedatoms;
     129    std::vector<AtomicInfo> clonedatominfos;
     130    for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin();
     131        iter != ClonedClusters.end(); ++iter) {
     132      const AtomIdSet &atoms = (*iter)->getAtomIds();
     133      clonedatoms.reserve(clonedatoms.size()+atoms.size());
     134      for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter)
     135        if (!filler->containsAtom(*atomiter)) {
     136          clonedatoms.push_back( *atomiter );
     137          clonedatominfos.push_back( AtomicInfo(*(*atomiter)) );
     138        }
    182139    }
    183 
    184     // remove
    185     delete mesh;
    186     delete inserter;
    187     delete voidnode_predicate;
    188     delete surface_predicate;
    189     delete LC;
    190     delete TesselStruct;
     140    std::vector< BondInfo > clonedbonds;
     141    StoreBondInformationFromAtoms(clonedatoms, clonedbonds);
     142    LOG(2, "DEBUG: There are " << clonedatominfos.size() << " newly created atoms.");
     143
     144    if (!successflag) {
     145      STATUS("Insertion failed, removing inserted clusters, translating original one back");
     146      RemoveAtomsFromAtomicInfo(clonedatominfos);
     147      clonedatoms.clear();
     148      SetAtomsFromAtomicInfo(movedatoms);
     149    } else {
     150      std::vector<Vector> MovedToVector(filler->size(), zeroVec);
     151      std::transform(filler->begin(), filler->end(), MovedToVector.begin(),
     152          boost::bind(&AtomInfo::getPosition, _1) );
     153      UndoState = new FillRegularGridState(clonedatominfos,clonedbonds,movedatoms,MovedToVector,params);
     154    }
    191155  }
    192156
Note: See TracChangeset for help on using the changeset viewer.