Implement Support for pymatgen.core.Molecule#200
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #200 +/- ##
==========================================
+ Coverage 81.38% 81.66% +0.28%
==========================================
Files 54 55 +1
Lines 4592 4690 +98
==========================================
+ Hits 3737 3830 +93
- Misses 855 860 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7bb91da to
b0ad014
Compare
| def remove_pbc(system, protect_layer = 9): | ||
| nframes = len(system["coords"]) | ||
| natoms = len(system['coords'][0]) | ||
| for ff in range(nframes): | ||
| tmpcoord = system['coords'][ff] | ||
| cog = np.average(tmpcoord, axis = 0) | ||
| dist = tmpcoord - np.tile(cog, [natoms, 1]) | ||
| max_dist = np.max(np.linalg.norm(dist, axis = 1)) | ||
| h_cell_size = max_dist + protect_layer | ||
| cell_size = h_cell_size * 2 | ||
| shift = np.array([1,1,1]) * h_cell_size - cog | ||
| system['coords'][ff] = system['coords'][ff] + np.tile(shift, [natoms, 1]) | ||
| system['cells'][ff] = cell_size * np.eye(3) | ||
| return system |
There was a problem hiding this comment.
It may not be a good idea to place remove_pbc here, because this method is not specific to pymatgen/molecule
There was a problem hiding this comment.
I moved "remove_pbc" to system.py. How is it now ?
| nframes = self.get_nframes() | ||
| natoms = self.get_natoms() | ||
| assert(protect_layer >= 0), "the protect_layer should be no less than 0" | ||
| for ff in range(nframes): | ||
| tmpcoord = self.data['coords'][ff] | ||
| cog = np.average(tmpcoord, axis = 0) | ||
| dist = tmpcoord - np.tile(cog, [natoms, 1]) | ||
| max_dist = np.max(np.linalg.norm(dist, axis = 1)) | ||
| h_cell_size = max_dist + protect_layer | ||
| cell_size = h_cell_size * 2 | ||
| shift = np.array([1,1,1]) * h_cell_size - cog | ||
| self.data['coords'][ff] = self.data['coords'][ff] + np.tile(shift, [natoms, 1]) | ||
| self.data['cells'][ff] = cell_size * np.eye(3) | ||
| remove_pbc(self.data, protect_layer) |
There was a problem hiding this comment.
I would recommend reverting the remove_pbc method in dpdata.System
There was a problem hiding this comment.
If this is leaved in class dpdata.System, how do I invoke it from pymatgen/molecule.py?
There was a problem hiding this comment.
where do you need remove_pbc in pymatgen/molecule.py? I do not find it
There was a problem hiding this comment.
Sorry for the late reply. Actually, I need remove_pbc in plugins/pymatgen.py. Specifically, in class PyMatgenMoleculeFormat(Format): def to_system(self, ...).
def remove_pbc()in toFormat.post("remove_pbc")system.py. And attributed it toPyMatgenMoleculeFormat.from_system()inplugins/pymatgen.py.def remove_pbc()to pymatgen/molecule.py.remove_pbc(data)before callingpymatgen.Molecule(coords = data['coords']), so to guarantee that the molecule doesn't get cut by cell boundaries.Unittest script: tests/test_pymatgen_molecule.py
Unittest files: tests/pymatgen/*