- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/WorldAction/RepeatBoxAction.cpp
r97ebf8 re30ce8 23 23 #include "UIElements/Dialog.hpp" 24 24 #include "Actions/MapOfActions.hpp" 25 #include "Descriptors/MoleculeDescriptor.hpp" 26 #include "Descriptors/MoleculePtrDescriptor.hpp" 25 27 26 28 const char WorldRepeatBoxAction::NAME[] = "repeat-box"; … … 40 42 molecule *mol = NULL; 41 43 int j = 0; 44 atom *Walker = NULL; 45 MoleculeListClass *molecules = World::getInstance().getMolecules(); 42 46 43 47 dialog->queryVector(NAME, &Repeater, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription(NAME)); 44 dialog->queryMolecule("molecule-by-id", &mol,MapOfActions::getInstance().getDescription("molecule-by-id")); 48 //dialog->queryMolecule("molecule-by-id", &mol,MapOfActions::getInstance().getDescription("molecule-by-id")); 49 vector<molecule *> AllMolecules; 50 if (mol != NULL) { 51 DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl); 52 AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol)); 53 } else { 54 DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl); 55 AllMolecules = World::getInstance().getAllMolecules(); 56 } 45 57 46 58 if(dialog->display()) { 59 (cout << "Repeating box " << Repeater << " times for (x,y,z) axis." << endl); 47 60 double * const cell_size = World::getInstance().getDomain(); 61 double *M = ReturnFullMatrixforSymmetric(cell_size); 48 62 Vector x,y; 49 for (int axis = 1; axis <= NDIM; axis++) {50 Vector ** vectors;63 int n[NDIM]; 64 for (int axis = 0; axis < NDIM; axis++) { 51 65 Repeater[axis] = floor(Repeater[axis]); 52 66 if (Repeater[axis] < 1) { … … 54 68 Repeater[axis] = 1; 55 69 } 56 mol->CountAtoms(); // recount atoms 57 if (mol->AtomCount != 0) { // if there is more than none 58 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand 59 Elements = new const element *[count]; 60 vectors = new Vector *[count]; 61 j = 0; 62 atom *first = mol->start; 63 while (first->next != mol->end) { // make a list of all atoms with coordinates and element 64 first = first->next; 65 Elements[j] = first->type; 66 vectors[j] = &first->x; 67 j++; 68 } 69 if (count != j) 70 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl); 71 x.Zero(); 72 y.Zero(); 73 y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 74 for (int i=1;i<Repeater[axis];i++) { // then add this list with respective translation factor times 75 x += y; // per factor one cell width further 76 for (int k=count;k--;) { // go through every atom of the original cell 77 first = World::getInstance().createAtom(); // create a new body 78 first->x = (*vectors[k]) + x; 79 first->type = Elements[k]; // insert original element 80 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) 70 cell_size[(abs(axis+1) == 2) ? 2 : ((abs(axis+2) == 3) ? 5 : 0)] *= Repeater[axis]; 71 } 72 73 molecule *newmol = NULL; 74 Vector ** vectors = NULL; 75 for (n[0] = 0; n[0] < Repeater[0]; n[0]++) { 76 y[0] = n[0]; 77 for (n[1] = 0; n[1] < Repeater[1]; n[1]++) { 78 y[1] = n[1]; 79 for (n[2] = 0; n[2] < Repeater[2]; n[2]++) { 80 y[2] = n[2]; 81 if (n[0] == n[1] == n[2] == 0) 82 continue; 83 for (vector<molecule *>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) { 84 mol = *MolRunner; 85 DoLog(1) && (Log() << Verbose(1) << "Current mol is " << mol->name << "." << endl); 86 count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand 87 if (count != 0) { // if there is more than none 88 Elements = new const element *[count]; 89 vectors = new Vector *[count]; 90 j = 0; 91 for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) { 92 Elements[j] = (*AtomRunner)->type; 93 vectors[j] = &(*AtomRunner)->x; 94 j++; 95 } 96 if (count != j) 97 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl); 98 x = y; 99 x.MatrixMultiplication(M); 100 newmol = World::getInstance().createMolecule(); 101 molecules->insert(newmol); 102 for (int k=count;k--;) { // go through every atom of the original cell 103 Walker = World::getInstance().createAtom(); // create a new body 104 Walker->x = (*vectors[k]) + x; 105 Walker->type = Elements[k]; // insert original element 106 cout << "new atom is " << *Walker << endl; 107 newmol->AddAtom(Walker); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) 108 } 109 // free memory 110 delete[](Elements); 111 delete[](vectors); 112 } else { 113 DoLog(1) && (Log() << Verbose(1) << "\t ... is empty." << endl); 114 } 81 115 } 82 116 } 83 // free memory84 delete[](Elements);85 delete[](vectors);86 // correct cell size87 if (axis < 0) { // if sign was negative, we have to translate everything88 x =(-(Repeater[axis]-1)) * y;89 mol->Translate(&x);90 }91 cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= Repeater[axis];92 117 } 93 118 } 119 delete(M); 94 120 delete dialog; 95 121 return Action::success;
Note:
See TracChangeset
for help on using the changeset viewer.