Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query for Filtering Between Force Thresholds #85

Open
htunstall opened this issue Feb 24, 2020 · 1 comment
Open

Query for Filtering Between Force Thresholds #85

htunstall opened this issue Feb 24, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@htunstall
Copy link

htunstall commented Feb 24, 2020

When doing some database querying I found it rather convoluted to filter by a min/max force component (so that you select all documents that have no forces outside these criteria) using standard mongodb terms.

The following query will only return documents with all its force components contained within the bounds of force_lim:

{"$and" : [
	{ "dft_forces" : { "$not" : { "$elemMatch" : { "$elemMatch" : { "$gt" :   force_lim }}}}},
	{ "dft_forces" : { "$not" : { "$elemMatch" : { "$elemMatch" : { "$lt" : - force_lim }}}}}
]}

You could also create an absolute max force component field and query it as such:

{"abs_max_fc"   : {"$lte" : force_lim}}

However creating this involves the following code:

for d in db.atoms.find({}):
    dft_forces = np.concatenate(d["dft_forces"], axis=0).flatten()
    
    new_data = np.amax(np.abs(dft_forces))
    new_tag  = "abs_max_fc"

    db.atoms.update({"_id": d["_id"]}, {"$set": {new_tag : new_data}})
    db.atoms.update_one({"_id": d["_id"]}, {"$push" : {"derived.derived_keys" : new_tag}})

A potential feature could be to make this more streamlined in future.

@gabor1
Copy link
Contributor

gabor1 commented Jan 13, 2021

same as #79

@gabor1 gabor1 added the enhancement New feature or request label Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants