|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * Fill a periodic cell with copies of a pre-equilibrated solvent box |
| 4 | + * (data/client/solvents/*.xyz) around a solute (#1118). Pure geometry on |
| 5 | + * coordinate lists: no Fragment, no wx, so it can be tested and driven from |
| 6 | + * a CLI. Lengths are Angstrom; the cell's origin is (0,0,0). |
| 7 | + * |
| 8 | + * A copy of a solvent molecule is kept when its centroid lies in the cell |
| 9 | + * and none of its atoms comes closer than scale*(r1+r2) (van der Waals |
| 10 | + * radii) to a solute atom, or solventScale*(r1+r2) to an atom of a solvent |
| 11 | + * molecule already kept, both by minimum image. The second test removes |
| 12 | + * the clashes where a box that is not a whole multiple of the template |
| 13 | + * meets its own periodic image. |
| 14 | + */ |
| 15 | +#ifndef SOLVATE_HH |
| 16 | +#define SOLVATE_HH |
| 17 | + |
| 18 | +#include <array> |
| 19 | +#include <string> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +namespace solvate { |
| 23 | + |
| 24 | +typedef std::array<double,3> Vec; |
| 25 | +typedef double Cell[3][3]; // rows are a, b, c |
| 26 | + |
| 27 | +struct SolventBox { |
| 28 | + std::string name; |
| 29 | + std::vector<std::string> symbols; // element symbols |
| 30 | + std::vector<std::string> types; // atom types as in the file (OW, HW) |
| 31 | + std::vector<Vec> xyz; |
| 32 | + int molSize; // atoms per molecule |
| 33 | + double edge[3]; // orthorhombic template box |
| 34 | + SolventBox() : molSize(0) { edge[0] = edge[1] = edge[2] = 0.0; } |
| 35 | + int molecules() const { return molSize > 0 ? (int)xyz.size() / molSize : 0; } |
| 36 | +}; |
| 37 | + |
| 38 | +/// Read "<natoms> <atoms per molecule>", "<a> <b> <c>", then TYPE x y z. |
| 39 | +bool readSolventBox(const std::string& path, SolventBox& box, |
| 40 | + std::string* err = 0); |
| 41 | +/// Names (file stems) of the solvent boxes in a directory, sorted. |
| 42 | +std::vector<std::string> solventNames(const std::string& dir); |
| 43 | + |
| 44 | +struct Options { |
| 45 | + double scale; // solute-solvent, times the sum of vdW radii |
| 46 | + double solventScale; // solvent-solvent across the cell boundary |
| 47 | + double margin; // Angstrom around the solute when there is no cell |
| 48 | + int maxAtoms; // refuse a fill larger than this |
| 49 | + Options() : scale(1.0), solventScale(0.57), margin(10.0), maxAtoms(2000000) {} |
| 50 | +}; |
| 51 | + |
| 52 | +struct Result { |
| 53 | + std::vector<std::string> symbols, types; |
| 54 | + std::vector<Vec> xyz; |
| 55 | + int molecules; |
| 56 | + Result() : molecules(0) {} |
| 57 | +}; |
| 58 | + |
| 59 | +/// Orthorhombic cell holding the solute's bounding box plus margin on every |
| 60 | +/// side; shift is what to add to the solute so it sits in the cell's middle. |
| 61 | +void marginCell(const std::vector<Vec>& solute, double margin, Cell out, |
| 62 | + Vec& shift); |
| 63 | + |
| 64 | +/// Solvent molecules to add. False and *err on a degenerate cell, an empty |
| 65 | +/// template or a fill above opt.maxAtoms. |
| 66 | +bool fill(const std::vector<std::string>& soluteSymbols, |
| 67 | + const std::vector<Vec>& soluteXyz, const Cell cell, |
| 68 | + const SolventBox& box, const Options& opt, Result& out, |
| 69 | + std::string* err = 0); |
| 70 | + |
| 71 | +/// Mass density (g/cm3) of the given atoms in the cell. |
| 72 | +double density(const std::vector<std::string>& symbols, const Cell cell); |
| 73 | + |
| 74 | +/// Water template (O, H, H per molecule)? |
| 75 | +bool isWater(const SolventBox& box); |
| 76 | + |
| 77 | +} // namespace solvate |
| 78 | + |
| 79 | +#endif |
0 commit comments