[ase-users] [ase-developers] Adjusting atom.momentum?

Jens Jørgen Mortensen jensj at fysik.dtu.dk
Mon Oct 24 07:40:22 CEST 2016


On 10/23/2016 01:27 AM, Ask Hjorth Larsen wrote:
> Hello
>
> An Atom now has a reference to the Atoms from which it was extracted.
>
> Therefore this is trivial to fix now.  It only requires the will to do so.

What has happened that makes it trivial to fix now and how would you do it?

Jens Jørgen

>
> Best regards
> Ask
>
> 2015-10-19 9:37 GMT+02:00 Jens Jørgen Mortensen <jensj at fysik.dtu.dk>:
>> On 10/16/2015 09:46 PM, Peterson, Andrew wrote:
>>
>> In writing the NVE test for the Hookean constraint, I noticed that modifying
>> the momentum attribute of an atom was not permanent. E.g.,
>>
>> In [1]: from ase.structure import molecule
>> In [2]: atoms = molecule('CH4')
>> In [3]: atoms[2].momentum[1] += 8.
>> In [4]: atoms.get_momenta()
>> Out[4]:
>> array([[ 0.,  0.,  0.],
>>         [ 0.,  0.,  0.],
>>         [ 0.,  0.,  0.],
>>         [ 0.,  0.,  0.],
>>         [ 0.,  0.,  0.]])
>>
>> I know I can use the set_momentum function, but had expected this to behave
>> the same as adjusting a position --- the analogous script with positions
>> does result in changing the position array:
>>
>> In [1]: from ase.structure import molecule
>> In [2]: atoms = molecule('CH4')
>> In [3]: atoms[2].position[1] += 8.
>> In [4]: atoms.get_positions()
>> Out[4]:
>> array([[ 0.      ,  0.      ,  0.      ],
>>         [ 0.629118,  0.629118,  0.629118],
>>         [-0.629118,  7.370882,  0.629118],
>>         [ 0.629118, -0.629118, -0.629118],
>>         [-0.629118,  0.629118, -0.629118]])
>>
>> Is this how it is supposed to work, or should I file an issue?
>>
>>
>> I guess you should file an issue.  I really don't know how to fix this.
>> Problem is that the momenta are zero even if you did not explicitly set them
>> and we don't want to allocate an ndarray for them before they become
>> non-zero.  The positions are always backed by an ndarray in the Atoms object
>> ...
>>
>> The best I can come of with is to make the ndarray you get from
>> atoms[2].momentum not writeable and document this weird behaviour.
>>
>> If the Atoms object already has momenta then it will work fine:
>>
>>      atoms[2].momentum = (0, 0, 0)
>>      atoms[2].momentum[1] += 8
>>
>> This will actually also work:
>>
>>      atoms[2].momentum += (0, 8, 0)
>>
>> Jens Jørgen
>>
>> thanks,
>> Andy
>>
>>
>> --
>> Andrew Peterson
>> Assistant Professor
>> Brown University School of Engineering
>> Barus & Holley 247
>> 184 Hope Street
>> Providence, RI 02912
>> (401) 863-2153
>> http://brown.edu/go/catalyst
>>
>>
>> _______________________________________________
>> ase-developers mailing list
>> ase-developers at listserv.fysik.dtu.dk
>> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-developers
>>
>>
>>
>> _______________________________________________
>> ase-developers mailing list
>> ase-developers at listserv.fysik.dtu.dk
>> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-developers



More information about the ase-users mailing list