Changeset d067d45 for src/molecules.cpp


Ignore:
Timestamp:
Jul 23, 2009, 1:45:24 PM (16 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:
51c910
Parents:
ce5ac3 (diff), 437922 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Frederik Heber <heber@…> (07/23/09 12:34:47)
git-committer:
Frederik Heber <heber@…> (07/23/09 13:45:24)
Message:

Merge branch 'MultipleMolecules'

Conflicts:

molecuilder/src/analyzer.cpp
molecuilder/src/atom.cpp
molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/datacreator.hpp
molecuilder/src/helpers.cpp
molecuilder/src/joiner.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp
molecuilder/src/parser.cpp
molecuilder/src/parser.hpp
molecuilder/src/vector.cpp
molecuilder/src/verbose.cpp

merges:

compilation fixes:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/molecules.cpp

    rce5ac3 rd067d45  
    6262  cell_size[0] = cell_size[2] = cell_size[5]= 20.;
    6363  cell_size[1] = cell_size[3] = cell_size[4]= 0.;
     64  strcpy(name,"none");
     65  IndexNr  = -1;
     66  ActiveFlag = false;
    6467};
    6568
     
    598601};
    599602
     603/** Set molecule::name from the basename without suffix in the given \a *filename.
     604 * \param *filename filename
     605 */
     606void molecule::SetNameFromFilename(const char *filename)
     607{
     608  int length = 0;
     609  char *molname = strrchr(filename, '/')+sizeof(char);  // search for filename without dirs
     610  char *endname = strchr(molname, '.');
     611  if ((endname == NULL) || (endname < molname))
     612    length = strlen(molname);
     613  else
     614    length = strlen(molname) - strlen(endname);
     615  strncpy(name, molname, length);
     616  name[length]='\0';
     617};
     618
    600619/** Sets the molecule::cell_size to the components of \a *dim (rectangular box)
    601620 * \param *dim vector class
     
    652671    max->Scale(0.5);
    653672    Translate(max);
     673    Center.Zero();
    654674  }
    655675
     
    691711    max->AddVector(min);
    692712    Translate(min);
     713    Center.Zero();
    693714  }
    694715  delete(min);
     
    700721 * \param *center return vector for translation vector
    701722 */
    702 void molecule::CenterOrigin(ofstream *out, Vector *center)
     723void molecule::CenterOrigin(ofstream *out)
    703724{
    704725  int Num = 0;
    705726  atom *ptr = start->next;  // start at first in list
    706727
    707   for(int i=NDIM;i--;) // zero center vector
    708     center->x[i] = 0.;
     728  Center.Zero();
    709729
    710730  if (ptr != end) {   //list not empty?
     
    712732      ptr = ptr->next;
    713733      Num++;
    714       center->AddVector(&ptr->x);
    715     }
    716     center->Scale(-1./Num); // divide through total number (and sign for direction)
    717     Translate(center);
     734      Center.AddVector(&ptr->x);
     735    }
     736    Center.Scale(-1./Num); // divide through total number (and sign for direction)
     737    Translate(&Center);
     738    Center.Zero();
    718739  }
    719740};
     
    780801 * \param *center return vector for translation vector
    781802 */
    782 void molecule::CenterGravity(ofstream *out, Vector *center)
    783 {
    784   if (center == NULL) {
    785     DetermineCenter(*center);
    786     Translate(center);
    787     delete(center);
    788   } else {
    789     Translate(center);
    790   }
     803void molecule::CenterPeriodic(ofstream *out)
     804{
     805  DeterminePeriodicCenter(Center);
     806};
     807
     808/** Centers the center of gravity of the atoms at (0,0,0).
     809 * \param *out output stream for debugging
     810 * \param *center return vector for translation vector
     811 */
     812void molecule::CenterAtVector(ofstream *out, Vector *newcenter)
     813{
     814  Center.CopyVector(newcenter);
    791815};
    792816
     
    837861
    838862/** Determines center of molecule (yet not considering atom masses).
    839  * \param Center reference to return vector
    840  */
    841 void molecule::DetermineCenter(Vector &Center)
     863 * \param center reference to return vector
     864 */
     865void molecule::DeterminePeriodicCenter(Vector &center)
    842866{
    843867  atom *Walker = start;
     
    849873
    850874  do {
    851     Center.Zero();
     875    center.Zero();
    852876    flag = true;
    853877    while (Walker->next != end) {
     
    876900        Testvector.AddVector(&Translationvector);
    877901        Testvector.MatrixMultiplication(matrix);
    878         Center.AddVector(&Testvector);
     902        center.AddVector(&Testvector);
    879903        cout << Verbose(1) << "vector is: ";
    880904        Testvector.Output((ofstream *)&cout);
     
    889913            Testvector.AddVector(&Translationvector);
    890914            Testvector.MatrixMultiplication(matrix);
    891             Center.AddVector(&Testvector);
     915            center.AddVector(&Testvector);
    892916            cout << Verbose(1) << "Hydrogen vector is: ";
    893917            Testvector.Output((ofstream *)&cout);
     
    900924  } while (!flag);
    901925  Free((void **)&matrix, "molecule::DetermineCenter: *matrix");
    902   Center.Scale(1./(double)AtomCount);
     926  center.Scale(1./(double)AtomCount);
    903927};
    904928
     
    913937  Vector *CenterOfGravity = DetermineCenterOfGravity(out);
    914938
    915   CenterGravity(out, CenterOfGravity);
     939  CenterAtVector(out, CenterOfGravity);
    916940
    917941  // reset inertia tensor
     
    14091433bool molecule::LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration)
    14101434{
     1435  molecule *mol = NULL;
    14111436  bool status = true;
    14121437  int MaxSteps = configuration.MaxOuterStep;
    1413   MoleculeListClass *MoleculePerStep = new MoleculeListClass(MaxSteps+1, AtomCount);
     1438  MoleculeListClass *MoleculePerStep = new MoleculeListClass();
    14141439  // Get the Permutation Map by MinimiseConstrainedPotential
    14151440  atom **PermutationMap = NULL;
     
    14431468  *out << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
    14441469  for (int step = 0; step <= MaxSteps; step++) {
    1445     MoleculePerStep->ListOfMolecules[step] = new molecule(elemente);
     1470    mol = new molecule(elemente);
     1471    MoleculePerStep->insert(mol);
    14461472    Walker = start;
    14471473    while (Walker->next != end) {
    14481474      Walker = Walker->next;
    14491475      // add to molecule list
    1450       Sprinter = MoleculePerStep->ListOfMolecules[step]->AddCopyAtom(Walker);
     1476      Sprinter = mol->AddCopyAtom(Walker);
    14511477      for (int n=NDIM;n--;) {
    14521478        Sprinter->x.x[n] = Trajectories[Walker].R.at(startstep).x[n] + (Trajectories[PermutationMap[Walker->nr]].R.at(endstep).x[n] - Trajectories[Walker].R.at(startstep).x[n])*((double)step/(double)MaxSteps);
     
    14671493  for (int i=AtomCount; i--; )
    14681494    SortIndex[i] = i;
    1469   status = MoleculePerStep->OutputConfigForListOfFragments(out, "ConstrainedStep", &configuration, SortIndex, false, false);
     1495  status = MoleculePerStep->OutputConfigForListOfFragments(out, &configuration, SortIndex);
    14701496 
    14711497  // free and return
     
    18281854};
    18291855
    1830 /** Removes atom from molecule list.
     1856/** Removes atom from molecule list and deletes it.
    18311857 * \param *pointer atom to be removed
    18321858 * \return true - succeeded, false - atom not found in list
     
    18421868  Trajectories.erase(pointer);
    18431869  return remove(pointer, start, end);
     1870};
     1871
     1872/** Removes atom from molecule list, but does not delete it.
     1873 * \param *pointer atom to be removed
     1874 * \return true - succeeded, false - atom not found in list
     1875 */
     1876bool molecule::UnlinkAtom(atom *pointer)
     1877{
     1878  if (pointer == NULL)
     1879    return false;
     1880  if (ElementsInMolecule[pointer->type->Z] != 0)  // this would indicate an error
     1881    ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element
     1882  else
     1883    cerr << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
     1884  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
     1885    ElementCount--;
     1886  Trajectories.erase(pointer);
     1887  unlink(pointer);
     1888  return true;
    18441889};
    18451890
     
    23682413            };
    23692414            AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
    2370            
     2415
    23712416          }
    23722417
     
    24842529                        //*out << Verbose(0) << "Current comparison atom is " << *OtherWalker << "." << endl;
    24852530                        /// \todo periodic check is missing here!
    2486                         //*out << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
     2531                        //*out << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    24872532                        MinDistance = OtherWalker->type->CovalentRadius + Walker->type->CovalentRadius;
    24882533                        MinDistance *= (IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem;
    24892534                        MaxDistance = MinDistance + BONDTHRESHOLD;
    24902535                        MinDistance -= BONDTHRESHOLD;
    2491                         distance =   OtherWalker->x.PeriodicDistance(&(Walker->x), cell_size);
     2536                        distance = OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size);
    24922537                        if ((OtherWalker->father->nr > Walker->father->nr) && (distance <= MaxDistance*MaxDistance) && (distance >= MinDistance*MinDistance)) { // create bond if distance is smaller
    2493                           //*out << Verbose(0) << "Adding Bond between " << *Walker << " and " << *OtherWalker << "." << endl;
     2538                          //*out << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;
    24942539                          AddBond(Walker->father, OtherWalker->father, 1);  // also increases molecule::BondCount
    2495                           BondCount++;
    24962540                        } else {
    24972541                          //*out << Verbose(1) << "Not Adding: Wrong label order or distance too great." << endl;
     
    25642608      *out << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    25652609    *out << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << bonddistance << ", " << FalseBondDegree << " bonds could not be corrected." << endl;
    2566    
     2610
    25672611    // output bonds for debugging (if bond chain list was correctly installed)
    25682612    *out << Verbose(1) << endl << "From contents of bond chain list:";
     
    31713215          cerr << "KeySet file must be corrupt as there are two equal key sets therein!" << endl;
    31723216        }
    3173         //FragmentList->ListOfMolecules[NumberOfFragments++] = StoreFragmentFromKeySet(out, CurrentSet, IsAngstroem);
    31743217      }
    31753218    }
     
    37313774  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    37323775    // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    3733     BondFragments = new MoleculeListClass(TotalGraph.size(), AtomCount);
     3776    BondFragments = new MoleculeListClass();
    37343777    int k=0;
    37353778    for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    37363779      KeySet test = (*runner).first;
    37373780      *out << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
    3738       BondFragments->ListOfMolecules[k] = StoreFragmentFromKeySet(out, test, configuration);
     3781      BondFragments->insert(StoreFragmentFromKeySet(out, test, configuration));
    37393782      k++;
    37403783    }
    3741     *out << k << "/" << BondFragments->NumberOfMolecules << " fragments generated from the keysets." << endl;
     3784    *out << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
    37423785
    37433786    // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    3744     if (BondFragments->NumberOfMolecules != 0) {
     3787    if (BondFragments->ListOfMolecules.size() != 0) {
    37453788      // create the SortIndex from BFS labels to order in the config file
    37463789      CreateMappingLabelsToConfigSequence(out, SortIndex);
    37473790
    3748       *out << Verbose(1) << "Writing " << BondFragments->NumberOfMolecules << " possible bond fragmentation configs" << endl;
    3749       if (BondFragments->OutputConfigForListOfFragments(out, FRAGMENTPREFIX, configuration, SortIndex, true, true))
     3791      *out << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
     3792      if (BondFragments->OutputConfigForListOfFragments(out, configuration, SortIndex))
    37503793        *out << Verbose(1) << "All configs written." << endl;
    37513794      else
     
    53185361  if (result) {
    53195362    *out << Verbose(5) << "Calculating Centers of Gravity" << endl;
    5320     DetermineCenter(CenterOfGravity);
    5321     OtherMolecule->DetermineCenter(OtherCenterOfGravity);
     5363    DeterminePeriodicCenter(CenterOfGravity);
     5364    OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity);
    53225365    *out << Verbose(5) << "Center of Gravity: ";
    53235366    CenterOfGravity.Output(out);
     
    53255368    OtherCenterOfGravity.Output(out);
    53265369    *out << endl;
    5327     if (CenterOfGravity.Distance(&OtherCenterOfGravity) > threshold) {
     5370    if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) {
    53285371      *out << Verbose(4) << "Centers of gravity don't match." << endl;
    53295372      result = false;
     
    53395382    while (Walker->next != end) {
    53405383      Walker = Walker->next;
    5341       Distances[Walker->nr] = CenterOfGravity.Distance(&Walker->x);
     5384      Distances[Walker->nr] = CenterOfGravity.DistanceSquared(&Walker->x);
    53425385    }
    53435386    Walker = OtherMolecule->start;
    53445387    while (Walker->next != OtherMolecule->end) {
    53455388      Walker = Walker->next;
    5346       OtherDistances[Walker->nr] = OtherCenterOfGravity.Distance(&Walker->x);
     5389      OtherDistances[Walker->nr] = OtherCenterOfGravity.DistanceSquared(&Walker->x);
    53475390    }
    53485391
     
    53625405    flag = 0;
    53635406    for (int i=0;i<AtomCount;i++) {
    5364       *out << Verbose(5) << "Distances: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl;
    5365       if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold)
     5407      *out << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl;
     5408      if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold)
    53665409        flag = 1;
    53675410    }
Note: See TracChangeset for help on using the changeset viewer.