Skip to content

fix bug in reading trajs with random tid#377

Merged
wanghan-iapcm merged 3 commits intodeepmodeling:develfrom
MabinogiX:devel
Nov 23, 2022
Merged

fix bug in reading trajs with random tid#377
wanghan-iapcm merged 3 commits intodeepmodeling:develfrom
MabinogiX:devel

Conversation

@MabinogiX
Copy link
Contributor

fix #376

Copy link
Contributor

@wanghan-iapcm wanghan-iapcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest an easier way of implementing the sorting according to type. Please check if I made anything wrong.

@@ -32,7 +43,8 @@ def get_atype(lines, type_idx_zero = False) :
atype = []
for ii in blk :
atype.append([int(ii.split()[id_idx]), int(ii.split()[tidx])])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
atype.append([int(ii.split()[id_idx]), int(ii.split()[tidx])])
atype.append([int(ii.split()[tid]), int(ii.split()[id_idx])])

posis.append([float(words[id_idx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])
posis.sort()
posis = np.array(posis)[:,1:4]
posis.append([float(words[id_idx]), float(words[tidx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
posis.append([float(words[id_idx]), float(words[tidx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])
posis.append([float(words[tidx]), float(words[id_idx]), float(words[xidx]), float(words[yidx]), float(words[zidx])])

Then we do not need to implement _sort_tid_comparator

Copy link
Contributor Author

@MabinogiX MabinogiX Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we do not need to implement _sort_tid_comparator
@wanghan-iapcm

_sort_tid_comparator is used so that there is only one possibility for sorting.
In this case, we may get multiple orders when sorting. For example:

# order1
id  type_id        x      y     z
1       1            1.0   1.0   1.0
2       1            2.0   2.0   2.0
3       2            3.0   2.0   2.0

# order2
id  type_id        x      y     z
2       1            2.0   2.0   2.0
1       1            1.0   1.0   1.0
3       2            3.0   2.0   2.0

Would this be OK?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check

In [33]: a = [[1, 2, 1], [1, 1, 3]]                                                                                                                                                   

In [34]: a.sort()                                                                                                                                                                     

In [35]: print(a)                                                                                                                                                                     
[[1, 1, 3], [1, 2, 1]]

@MabinogiX
Copy link
Contributor Author

Complete!

@codecov-commenter
Copy link

Codecov Report

Base: 82.28% // Head: 82.37% // Increases project coverage by +0.09% 🎉

Coverage data is based on head (5d95009) compared to base (afc02c4).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #377      +/-   ##
==========================================
+ Coverage   82.28%   82.37%   +0.09%     
==========================================
  Files          67       67              
  Lines        5898     5908      +10     
==========================================
+ Hits         4853     4867      +14     
+ Misses       1045     1041       -4     
Impacted Files Coverage Δ
dpdata/lammps/dump.py 90.42% <100.00%> (+0.15%) ⬆️
dpdata/gromacs/gro.py 98.76% <0.00%> (+0.01%) ⬆️
dpdata/xyz/quip_gap_xyz.py 93.16% <0.00%> (+0.05%) ⬆️
dpdata/qe/traj.py 81.20% <0.00%> (+0.25%) ⬆️
dpdata/cp2k/output.py 97.84% <0.00%> (+0.32%) ⬆️
dpdata/lammps/lmp.py 80.25% <0.00%> (+0.76%) ⬆️
dpdata/plugins/__init__.py 94.44% <0.00%> (+11.11%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@wanghan-iapcm wanghan-iapcm merged commit efbaae6 into deepmodeling:devel Nov 23, 2022
@njzjz njzjz linked an issue Nov 24, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bug in reading lammps trajectory files with random type id

3 participants