You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The grid-based distance search in NSGrid works for an fcc crystal in a triclinic box.
Actual behavior
When calculating coordination numbers for all atoms in the correctly reproduced fcc-system from #2345, the NSGrid-based result is wrong. The test testsuite/MDAnalysisTests/lib/test_nsgrid.py::test_issue_2670 passes only because it loads the system from a pdb file, which lacks the coordinate precision required to reproduce the issue.
Code to reproduce the behavior
fromcollectionsimportdefaultdict, Counterfromnumpy.testingimportassert_allcloseimportnumpyasnpimportMDAnalysisasmdafromMDAnalysisTests.datafilesimportSURFACE_PDB, SURFACE_TRRfromMDAnalysis.lib.distancesimportdistance_array, apply_PBCfromMDAnalysis.lib.mdamathimporttriclinic_box, triclinic_vectorsfromMDAnalysis.lib.nsgridimportFastNSfromase.buildimportfcc111#search radius:cutoff=2.9print("selected cutoff: {}".format(cutoff))
#generate triclinic fcc slab system with ASE:ase_system=fcc111('Ag', size=(5, 5, 4), vacuum=10.0)
ase_box=triclinic_box(*ase_system.cell)
ase_positions=ase_system.positions.astype(np.float32)
#load similar system from corresponding PDB file:u=mda.Universe(SURFACE_PDB)
pdb_box=u.dimensionspdb_positions=u.atoms.positions# Assert that systems are almost equal. PDB rounds to 3 decimal places so that# the difference must not be larger than 0.0005:assert_allclose(ase_box, pdb_box, atol=0.0005)
assert_allclose(ase_positions, pdb_positions, atol=0.0005)
#print boxes:print()
print("ASE box: [{}]""".format(" ".join(["{:15.10f}"] *len(ase_box))).format(*ase_box))
print("PDB box: [{}]""".format(" ".join(["{:15.10f}"] *len(pdb_box))).format(*pdb_box))
#ASE bruteforce distance search:ase_da=distance_array(ase_positions, ase_positions, box=ase_box)
ase_bf_cn= []
foriinrange(ase_da.shape[0]):
ase_bf_cn.append(len([ixforixinrange(ase_da.shape[1])
if0.0<ase_da[i, ix] <cutoff]))
bf_cns, bf_cn_counts=np.unique(ase_bf_cn, return_counts=True)
ase_bf_cn=dict(list(zip(list(bf_cns), list(bf_cn_counts))))
#ASE grid-based distance search:ase_fns=FastNS(cutoff=cutoff, coords=ase_positions, box=ase_box, pbc=True)
ase_fns_results=ase_fns.self_search()
ase_nsgrid_pairs=ase_fns_results.get_pairs()
ase_nsgrid_indices=defaultdict(list)
fori, jinase_nsgrid_pairs:
ase_nsgrid_indices[i].append(j)
ase_nsgrid_indices[j].append(i)
ase_nsgrid_cn=dict(Counter(len(v) forvinase_nsgrid_indices.values()))
#PDB bruteforce distance search:pdb_da=distance_array(pdb_positions, pdb_positions, box=pdb_box)
pdb_bf_cn= []
foriinrange(pdb_da.shape[0]):
pdb_bf_cn.append(len([ixforixinrange(pdb_da.shape[1])
if0.0<pdb_da[i, ix] <cutoff]))
bf_cns, bf_cn_counts=np.unique(pdb_bf_cn, return_counts=True)
pdb_bf_cn=dict(list(zip(list(bf_cns), list(bf_cn_counts))))
#PDB grid-based distance search:pdb_fns=FastNS(cutoff=cutoff, coords=pdb_positions, box=pdb_box, pbc=True)
pdb_fns_results=pdb_fns.self_search()
pdb_nsgrid_pairs=pdb_fns_results.get_pairs()
pdb_nsgrid_indices=defaultdict(list)
fori, jinpdb_nsgrid_pairs:
pdb_nsgrid_indices[i].append(j)
pdb_nsgrid_indices[j].append(i)
pdb_nsgrid_cn=dict(Counter(len(v) forvinpdb_nsgrid_indices.values()))
# print results:print()
print("ASE brute force coordination numbers: {}".format(ase_bf_cn))
print("PDB brute force coordination numbers: {}".format(pdb_bf_cn))
print()
print("ASE NSGrid coordination numbers: {}".format(ase_nsgrid_cn))
print("PDB NSGrid coordination numbers: {}".format(pdb_nsgrid_cn))
Expected behavior
The grid-based distance search in
NSGrid
works for an fcc crystal in a triclinic box.Actual behavior
When calculating coordination numbers for all atoms in the correctly reproduced fcc-system from #2345, the NSGrid-based result is wrong. The test
testsuite/MDAnalysisTests/lib/test_nsgrid.py::test_issue_2670
passes only because it loads the system from a pdb file, which lacks the coordinate precision required to reproduce the issue.Code to reproduce the behavior
Output:
Current version of MDAnalysis
The text was updated successfully, but these errors were encountered: