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

CP2K enhancements #67

Merged
merged 25 commits into from Nov 20, 2020
Merged

CP2K enhancements #67

merged 25 commits into from Nov 20, 2020

Conversation

patrickmelix
Copy link
Contributor

@patrickmelix patrickmelix commented May 24, 2019

Hey,

just saw that there are some minor changes in #66 that affect the CP2K interface I'm also still working on. Sorry for not putting that here earlier, didn't know somebody else is working on it too and was busy with something else in the meantime.

I also added the unit option for the energies here, so this might conflict with #66. Also there's now some things around MDs.

Not final yet, feel free to request changes (especially @BvB93 ).
Cheers,
Patrick

@BvB93
Copy link
Collaborator

BvB93 commented May 24, 2019

Hi Patrick,

The changes you've made look just fine to me.
As you've already added the unit keyword in your branch, i'll remove it from #66 for the sake of minimizing redundancy.

Regards, Bas

@patrickmelix
Copy link
Contributor Author

Awesome, thanks. And sorry for not pushing earlier...

@patrickmelix patrickmelix changed the title WIP: CP2K enhancements CP2K enhancements Jul 22, 2020
@patrickmelix
Copy link
Contributor Author

I think nothing more is coming any time soon from me. Sorry for the delay. Could be merged.

@patrickmelix
Copy link
Contributor Author

Cleaning my ToDo-List: Anything more for me to do @BvB93?

Copy link
Collaborator

@BvB93 BvB93 left a comment

Choose a reason for hiding this comment

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

A few, mostly style-related, comments but overall I feel these are nice additions.
The only thing that I find a bit concerning is Cp2kResults.get_energy() returning a list rather than a float, as it is the only Job.get_energy() which does so.

Secondly, Michal just said that he'll take a look at the open PRs, which should help with the whole merging thing.

interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Show resolved Hide resolved
patrickmelix and others added 12 commits October 29, 2020 08:52
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
@patrickmelix
Copy link
Contributor Author

Thx for the input @BvB93, very good!

Copy link
Collaborator

@BvB93 BvB93 left a comment

Choose a reason for hiding this comment

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

Really liking the changes!
I've got a few more documentation-related questions/remarks but in my opinion the PR is good to go afterwards.

interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
ret.append([])
continue
ret[-1].append(line[-3:])
return [np.array(item, dtype=float) for item in ret]
Copy link
Collaborator

@BvB93 BvB93 Oct 29, 2020

Choose a reason for hiding this comment

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

By the way, I assume these arrays are of all different shapes and thus we can't coerce the final result into a single array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess in almost all cases they will be the same length. But in any simulation without constant number of particles, the array length might differ between frames. Not sure if there is any calculation in CP2K that allows this (perhaps some embedded schemes?!), but I guess this way we are on the safe side...

Copy link
Collaborator

@BvB93 BvB93 Oct 29, 2020

Choose a reason for hiding this comment

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

I guess in almost all cases they will be the same length.

By the sound of it the this would entail the vast majority (all?) cases.

How about converting the whole thing into an ndarray via a try / except approach,
using a ragged array as fallback if necessary?

import warnings
import numpy as np

def _sequence_to_array(seq, dtype=float):
    """Convert the (nested) sequence *seq* into an array with the specified *dtype*.
    
    If *seq* is ragged sequence it will be converted into a ragged object array instead.
    """
    try:
        return np.array(seq, dtype=dtype)
    except ValueError as ex:
        # Create and return a ragged array, 
        # i.e. an object array whose elements are normal arrays
        ret = np.empty(len(seq), dtype=object)
        ret[:] = [np.array(item, dtype=dtype) for item in seq]

        warning = RuntimeWarning(f"Failed to coerce the forces into a single {np.dtype(dtype)} array;"
                                 "returning a ragged array instead")
        warning.__cause__ = ex
        warnings.warn(warning, stacklevel=3)
        return ret

class Cp2kResults:
    get_forces(...):
        ...
        return _sequence_to_array(ret)

interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
interfaces/thirdparty/cp2k.py Outdated Show resolved Hide resolved
patrickmelix and others added 3 commits October 29, 2020 12:10
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
@BvB93
Copy link
Collaborator

BvB93 commented Oct 29, 2020

@felipeZ do you have any comments?
Considering this entails a Cp2kJob / Cp2kResult enhancement.

@h4nsu h4nsu merged commit 05092af into SCM-NV:master Nov 20, 2020
@patrickmelix patrickmelix deleted the cp2k branch November 23, 2020 08:03
h4nsu added a commit that referenced this pull request Dec 15, 2020
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.

None yet

3 participants