Trajectory momenta

79 views
Skip to first unread message

Nicolas Künzel

unread,
Aug 29, 2017, 5:05:56 AM8/29/17
to ipi-users
Hello,

I've got a problem when printing out the trajectory. When I want to print out momenta I found in the code that this is just possible in atomic units right now which wouldn't be a problem. But when I just leave the unit brackets {} empty or just don't write them at all I get the following error:

Traceback (most recent call last):
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 101, in <module>
    main(args[0], options.do_yappi)
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 51, in main
    simulation.run()
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/simulation.py", line 219, in run
    o.write()  # threaded output seems to cause random hang-ups. should make things properly thread-safe
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/outputs.py", line 318, in write
    self.system.trajs.print_traj(self.what, self.out, b=0, format=self.format, cell_units=self.cell_units, flush=doflush)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/properties.py", line 2297, in print_traj
    fatom.q = cq
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 802, in __setattr__
    return obj.__set__(self, value)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 614, in __set__
    self.__setitem__(slice(None, None), value=value)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 590, in __setitem__
    self.view(np.ndarray)[index] = value
ValueError: could not broadcast input array from shape (16,3) into shape (3)


The lines I tried in the input file are:

<trajectory filename='momenta.out' stride='1' format='xyz' cell_units='angstrom'> momenta{} </trajectory>
<trajectory filename='momenta.out' stride='1' format='xyz' cell_units='angstrom'> momenta </trajectory>

Or when I try to write atomic units in the brackets it tells me:

Traceback (most recent call last):
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 101, in <module>
    main(args[0], options.do_yappi)
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 51, in main
    simulation.run()
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/simulation.py", line 219, in run
    o.write()  # threaded output seems to cause random hang-ups. should make things properly thread-safe
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/outputs.py", line 318, in write
    self.system.trajs.print_traj(self.what, self.out, b=0, format=self.format, cell_units=self.cell_units, flush=doflush)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/properties.py", line 2281, in print_traj
    cq = self[what]
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/properties.py", line 2264, in __getitem__
    return  unit_to_user(pkey["dimension"], unit, 1.0) * pkey["func"](*arglist,**kwarglist)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/units.py", line 347, in unit_to_user
    return number / unit_to_internal(family, unit, 1.0)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/units.py", line 330, in unit_to_internal
    raise TypeError(base + " is an undefined unit for kind " + family + ".")
TypeError: atomic units is an undefined unit for kind momentum.


Doing the same with positions and the right units (angstrom) in the brackets that works well.

Am I doing something wrong?

Kind regards

Nicolas Künzel

venkat kapil

unread,
Aug 29, 2017, 5:42:02 AM8/29/17
to ipi-users
Hello Nicolas, 

I tried these and I get the same output without any error.

<trajectory filename="pos" stride="1" format='xyz' cell_units='angstrom'> momenta{} </trajectory>
<trajectory filename="pos" stride="1" format='xyz' cell_units='angstrom'> momenta </trajectory>
<trajectory filename="pos" stride="1" format='xyz' cell_units='angstrom'> momenta{atomic_unit} </trajectory>

Note that I specified "atomic_unit" and not  "atomic_units". 

Can you share with me your input.xml that gave you the error:


Traceback (most recent call last):
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 101, in <module>
    main(args[0], options.do_yappi)
  File "/data/nk158/i-PI-dev/trunk/bin/i-pi", line 51, in main
    simulation.run()
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/simulation.py", line 219, in run
    o.write()  # threaded output seems to cause random hang-ups. should make things properly thread-safe
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/outputs.py", line 318, in write
    self.system.trajs.print_traj(self.what, self.out, b=0, format=self.format, cell_units=self.cell_units, flush=doflush)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/engine/properties.py", line 2297, in print_traj
    fatom.q = cq
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 802, in __setattr__
    return obj.__set__(self, value)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 614, in __set__
    self.__setitem__(slice(None, None), value=value)
  File "/cluster/data/nk158/i-PI-dev/trunk/ipi/utils/depend.py", line 590, in __setitem__
    self.view(np.ndarray)[index] = value
ValueError: could not broadcast input array from shape (16,3) into shape (3)


Also, are which version / branch of i-pi are you using  ?

Best,
Venkat

Michele Ceriotti

unread,
Aug 29, 2017, 5:44:43 AM8/29/17
to ipi-users
Dear Nicolas, 
    I should add: units are a sore point in i-PI, and there is a branch in which we're trying to fix things once and for all. If you want to contribute to the code, and/or to share your thoughts, that is a very good place to start. https://github.com/cosmo-epfl/i-pi-dev/pull/188
Thanks

Nicolas Künzel

unread,
Aug 29, 2017, 5:58:42 AM8/29/17
to ipi-users
Oh sorry, forgot to write that. I am using the code from i-PI-dev/trunk right now.

The input file which gave the error is actually RESTART file which I modified for which new trajectory output:

<simulation>
   <total_steps>999999</total_steps>
   <output prefix=''>
      <trajectory filename='momenta_equi.out' stride='100' format='xyz' cell_units='angstrom'> momenta </trajectory>
      <trajectory filename='positions_equi.out' stride='100' cell_units='angstrom'>positions{angstrom}</trajectory>
      <checkpoint stride='100' overwrite='False' filename='harm.checkpoint'>1</checkpoint>
      <properties filename='harm.out' stride='1000' shape='(6)'>
       [ step, time{picosecond}, conserved{kelvin}, temperature{kelvin}, kinetic_cv{kelvin},
         potential{kelvin} ]
      </properties>
   </output>
   <prng>
      <set_pos>224</set_pos>
      <state shape='(624)'>
       [ 3108168615, 4206567321, 3726570625, 3956537760, 2085139183,
         2706759315, 3624124414, 3557979264, 3155160282, 1285496459,
         1769130790, 252762920, 2620322071, 557428496, 3664791698,
         3808559739, 1099279667, 1340883364, 1522169436, 2009169158,
         394927140, 947416969, 4091007474, 422282600, 4043733511,
         3009089145, 4151630818, 756884779, 1004426120, 58108631,
         1541203454, 3058315092, 1838953475, 3432581869, 1782417976,
         1849415954, 1309133892, 3452985253, 4169031813, 2357453320,
         2957199501, 594762015, 417501258, 3924609587, 1168205166,
         743426973, 3684557733, 4205308445, 2293313451, 2109438312,
         2356865300, 3873070904, 3756849677, 2943651032, 3910956297,
         2616301087, 2016370720, 468479938, 1163067534, 1720944904,
         4156398758, 1056868507, 2534423308, 1635832107, 3402474515,
         2255153890, 3799496404, 3506101171, 885075538, 2737903004,
         2026067569, 1436355588, 816332211, 2994026466, 1307774785,
         2150552994, 2857093569, 1513669041, 1909719042, 1567594909,
         2272570245, 316035914, 2449706264, 2065344720, 3883266025,
         1298942755, 2745414966, 1160859916, 71086989, 381876810,
         1019998053, 3929676491, 2248790064, 1407514498, 2116034624,
         2684127617, 429073147, 2251237173, 3246555098, 63634006,
         447118830, 3243557861, 1297108620, 4279706005, 2571091560,
         4288280718, 343834444, 834841883, 2827616815, 1432741425,
         3624963987, 581933505, 4209878231, 323497046, 1451571677,
         2413566397, 993170118, 1776406432, 1062261211, 4139886425,
         3493134312, 4010020927, 3618627248, 2663449024, 3549239253,
         2152632282, 2470114109, 4243017413, 2552024888, 529582048,
         2035718517, 2184832412, 3730924233, 1909033335, 2623128353,
         2834984514, 2436533459, 2759687600, 956111416, 2391431264,
         3948863540, 430993890, 111707134, 4201275751, 2181430201,
         1237855709, 2848450356, 1646071893, 3395316387, 1894377150,
         1732972278, 2560935268, 1387857141, 654090296, 3759204083,
         2758279379, 3506918905, 1563643097, 2278729423, 2110568368,
         706458973, 3718385549, 1225861036, 3149278027, 3897582842,
         2342041888, 18865826, 3227320773, 4294802642, 966488679,
         918087665, 3162306802, 2338633445, 2952349646, 1692363912,
         3166206588, 1254859880, 1780759845, 1221474283, 846036446,
         193780146, 3866999456, 349608239, 673975154, 3218815297,
         1505997195, 2424547167, 1513096496, 2390865672, 2258229102,
         1020355881, 1287131511, 1124252492, 2273743252, 1550585666,
         8033401, 569703167, 3663424469, 86439995, 3646397240,
         4252785605, 2551570899, 2413503172, 3788189982, 3898246013,
         356141052, 1163357682, 2161338155, 597717363, 3237720262,
         2330361380, 507265387, 2948918293, 1817019860, 1602553328,
         4061003221, 3614509829, 3992667151, 2093445739, 661197671,
         3503055918, 1818798468, 2666866221, 3006803019, 3728703639,
         748859203, 3420577209, 2734228680, 2548447036, 1730358659,
         7837002, 1095383654, 926096912, 2365849050, 2915553230,
         2482182010, 2871537436, 2069414402, 2176299204, 515641854,
         3290102807, 3891396009, 1551210934, 479303109, 2136064267,
         1293537251, 1135362466, 403360548, 3652591693, 4206506776,
         1127435024, 1789008677, 3923818583, 3593665136, 2008735086,
         307060069, 3914284027, 2887690591, 751920378, 1984566131,
         1583633572, 2272605696, 1347429453, 1774986224, 2455596658,
         3534976159, 3921906333, 1602610826, 1099376071, 527695593,
         4059365839, 1248275490, 3139790789, 574647542, 736727521,
         2487291587, 479125661, 2878893175, 2363309156, 2937297376,
         1904030842, 3701891161, 3904652108, 511327887, 2333354200,
         918623083, 2124648135, 3821787059, 3069316187, 417304700,
         2806913512, 4148415273, 2260954985, 1394361693, 443153066,
         1841729122, 882087737, 2993899527, 2970995128, 427988456,
         794925441, 3322062946, 1019543033, 3331380317, 4247648895,
         267737292, 1498346821, 1124988834, 3510916975, 4274237822,
         3499606158, 3331998118, 2010877826, 4235371433, 758081350,
         3751023549, 978590782, 2111124750, 15440285, 2238173583,
         1285224434, 2034678583, 2463429607, 2964831244, 500396161,
         4161593751, 1926399363, 2674904381, 3146730817, 2562640172,
         2236279984, 3971500871, 2303081147, 1141481057, 1693007442,
         3237095835, 393081876, 943308307, 611814464, 2195429141,
         3819289616, 825158510, 3768401169, 2100972897, 1137579461,
         1745848547, 3768649168, 2625600560, 2563167091, 232347549,
         3339184505, 1431536516, 777358857, 741432913, 2081229074,
         2261689573, 732142322, 1338858251, 333031149, 4285714304,
         3344824488, 3889551324, 4154879951, 1968047171, 2924169614,
         1691963836, 1249902342, 788683324, 3585883245, 3901931408,
         1370095100, 3014371354, 705568205, 4214604898, 2341347855,
         2293619095, 3271723464, 783996137, 1848829922, 371582345,
         4092614919, 4243708296, 26692912, 572937834, 237783251,
         3726365010, 165166315, 526399292, 3187281345, 220924508,
         2467255795, 2598875695, 3081082982, 3070978730, 104856380,
         790783010, 1417981574, 737426290, 2479479522, 3988480854,
         2785927245, 2798923980, 1291722919, 2604209544, 1255684670,
         2853933054, 2880790225, 1502858734, 1052781563, 866700992,
         3426994471, 3017425492, 152050704, 1330308435, 1940366448,
         277996533, 590274892, 101197322, 1186175313, 881961050,
         3528037078, 2960652604, 1928253632, 2263353652, 564673487,
         1490410893, 1717330343, 2466739295, 2494278047, 2143295546,
         436912240, 2382428409, 2157307619, 1775680358, 2026946646,
         2314481491, 3987019420, 1557217588, 2128134685, 3210867873,
         1992080445, 3010376146, 25597329, 1842507161, 3827460314,
         2636595346, 2675845524, 2227452521, 2324716713, 643200054,
         4220999811, 3346581983, 1812617182, 1095619889, 1319993422,
         3448462055, 1296913744, 545870991, 4132797748, 2900405794,
         3435388666, 1347763263, 808762049, 1061907346, 1780239546,
         59710898, 2832895213, 2115275253, 2374112376, 2704611725,
         1465457779, 3575926868, 2279705286, 1314457690, 593319521,
         1412641450, 3467693635, 1309264619, 370050982, 3990437111,
         2415003868, 1371796990, 2515793359, 4212483151, 2756076940,
         3939131836, 113864124, 1071639884, 1111345739, 1664475927,
         1815692213, 3332826343, 225835709, 396724981, 3304961510,
         1175315456, 3000888907, 2517520657, 2425172804, 312322663,
         3524099670, 101464041, 787660501, 3688665179, 2658061306,
         4231940469, 2614401557, 4054282590, 2892322992, 3119899520,
         987829842, 4237479217, 665832702, 2547099271, 3142917862,
         3037577174, 635963167, 3230898302, 2342166013, 3025723239,
         2933718236, 2800056902, 3874588287, 529075358, 4171191974,
         3741824347, 2614457478, 3134810170, 1888809473, 1455189270,
         1236565142, 2610607816, 709757402, 535735532, 3338782850,
         884794406, 1653491392, 1446162091, 4144829225, 2419329236,
         1458566352, 1911568045, 2797220769, 3048573805, 2175905354,
         1968983655, 3932130889, 2768743899, 769952662, 4184084592,
         3938114150, 430959480, 3090334665, 2587722300, 309086105,
         2080354263, 797075874, 1551573, 1210880450, 659752933,
         2397361637, 62646447, 3002261258, 2307810416, 1228350589,
         511106673, 393771228, 865040030, 2401529333, 97655129,
         1814251699, 2133466415, 385090206, 1399769378, 3291303056,
         794560286, 12399698, 1116823219, 2519773246, 3290727547,
         303953678, 2195632513, 1152004892, 578810162, 4124355681,
         2457762196, 83017584, 3617022992, 1765383646, 4270300180,
         859743626, 3169358801, 2091496370, 1164707874, 1167481638,
         4101470003, 125702195, 2258005032, 1436558886, 2952244076,
         3121350672, 1426185931, 1563610687, 3106329715, 3845498583,
         1001829354, 1099620441, 2583438266, 97746371, 3999408446,
         2280808171, 33015111, 622654564, 482007031, 4171859210,
         3481413659, 2788434966, 489563051, 1948275747, 1924649845,
         2502326987, 3568780040, 2915156545, 3509415818 ]
      </state>
      <seed>12345</seed>
   </prng>
   <ffsocket mode='unix' name='driver'>
      <address>harmonic</address>
   </ffsocket>
   <system>
   <cell shape='(3, 3)'>
       [   7.12300000e+01,   4.36157958e-15,   4.36157958e-15,   0.00000000e+00,   7.12300000e+01,
           4.36157958e-15,   0.00000000e+00,   0.00000000e+00,   7.12300000e+01 ]
      </cell>
      <beads natoms='1' nbeads='16'>
         <q shape='(16, 3)'>
          [   1.88907329e-01,   7.51845101e-02,  -3.19296116e-01,   1.48953476e-01,   1.35069016e-01,
             -3.79431077e-01,   4.96233314e-02,   1.95566669e-01,   4.91768771e-02,   3.20555142e-02,
              2.23738717e-01,   9.82927845e-02,   5.07584155e-02,   2.86206026e-01,   3.39503441e-02,
              8.41500588e-02,   1.32632793e-01,   1.23904251e-01,   2.24483270e-01,  -1.41156614e-02,
              7.77168615e-02,   3.73530763e-02,  -1.24259109e-01,  -7.08415112e-02,   2.44764677e-01,
             -1.70514684e-01,   1.67063189e-01,   1.81640194e-01,  -1.90398168e-01,  -4.74470079e-02,
              2.04980085e-02,  -9.62702656e-02,  -3.84416585e-02,   7.04345481e-02,  -6.15469887e-02,
              1.39590667e-01,   2.05174977e-01,   8.45679902e-02,   2.93005504e-01,   9.81576663e-02,
             -2.21862822e-01,   2.14780548e-01,   1.14083084e-01,  -1.83612788e-01,  -5.50152437e-02,
             -2.30376083e-02,  -7.03852229e-02,  -2.87008390e-01 ]
         </q>
         <p shape='(16, 3)'>
          [   4.17181066e+00,  -2.95221787e+00,  -1.83124148e+00,  -5.65860372e+00,   2.48461107e+00,
              7.74276387e-01,  -4.27301629e+00,  -4.74448173e+00,   8.72810299e+00,  -2.51411019e+00,
              5.90233480e+00,   1.83208315e+00,  -6.92933954e-01,   5.23644409e+00,   5.97102040e+00,
              2.00169622e+00,  -5.33292625e+00,   2.02716969e+00,   5.21534630e+00,  -7.22261682e-01,
             -7.30296509e+00,   1.32767035e+00,  -5.52669840e+00,  -2.96889104e-01,   3.30114905e+00,
             -6.93725519e+00,  -7.49233211e-01,  -1.87718448e+00,   9.15706306e-01,  -3.19352732e+00,
             -3.14251693e+00,   2.51910213e+00,   1.34555278e+00,   3.70208238e+00,   6.13942905e+00,
              2.32457427e+00,  -2.13779300e+00,   1.03100499e+00,  -6.54773035e+00,  -1.28143362e+01,
              2.16506234e+00,  -1.12011997e+00,   3.05580855e-01,   3.21252770e+00,  -1.48306554e+00,
              1.30851589e+01,  -3.39038136e+00,  -4.78007603e-01 ]
         </p>
         <m shape='(1)'> [   1.83736223e+03 ] </m>
         <names shape='(1)'> [ H ] </names>
      </beads>
      <motion mode='dynamics'>
         <dynamics mode='nvt'>
            <timestep>  1.24024119e-01</timestep>
            <nmts shape='(1)'> [ 1 ] </nmts>
            <thermostat mode='langevin'>
               <tau>  1.03353433e+03</tau>
               <ethermo> -4.47895941e-01</ethermo>
            </thermostat>
         </dynamics>
      </motion>
      <forces>
         <force forcefield='driver'>
         </force>
      </forces>
      <ensemble>
         <temperature>  9.50044560e-04</temperature>
      </ensemble>
   </system>
</simulation>

Nicolas Künzel

unread,
Aug 29, 2017, 6:47:05 AM8/29/17
to ipi-users
I tried to use the inputs you are writing there and I get the same error again.

Michele Ceriotti

unread,
Aug 29, 2017, 7:00:05 AM8/29/17
to ipi-users
This is weird. Since there is no "trunk" branch I assume you are using i-pi-dev/master. Are you sure there isn't something silly like input encoding messing up some of the special characters, etc?
I tried Venkat's example, and works flawlessly here.

Nicolas Künzel

unread,
Aug 29, 2017, 8:41:23 AM8/29/17
to ipi-users
Ok,
I think I just download i-PI again and set it up new. Which branches would you recommend? I guess the master branch would be the right one?

Before I checked out the i-pi-dev via svn from github and in the resulting folder there are two folders: branches and trunk.
I thought the trunk folder would be the right one to work in since in the branches folder there is no master folder.

But I just download the master branch now as zip file and then that should work.

Nicolas Künzel

unread,
Aug 29, 2017, 9:33:01 AM8/29/17
to ipi-users
I am now using the i-pi-master branch and getting the same error.

But I realized that it first happens, when I connect the driver code. Just the reading of the input file works but when connecting the driver in order to start the MD run I get this error.
I tried it in the examples/harmonic/ right now.

Nicolas Künzel

unread,
Aug 29, 2017, 10:10:17 AM8/29/17
to ipi-users
Could that be a problem with the python version or the installation on our server?

venkat kapil

unread,
Aug 29, 2017, 10:32:03 AM8/29/17
to ipi-users
I tried your input and got the same error. 

Michele Ceriotti

unread,
Aug 29, 2017, 10:39:13 AM8/29/17
to ipi-users
OK, so there is a minimal working example. Looks like a very weird bug, all the other inputs are working just fine. At this point it's probably best you file a bug on github so we can track it from there.

Nicolas Künzel

unread,
Aug 29, 2017, 10:57:05 AM8/29/17
to ipi-users
Ok. I have done that.
So until then I won't be able to check the momentum distributions for my calculations?

Nicolas Künzel

unread,
Aug 29, 2017, 1:12:02 PM8/29/17
to ipi-users
Thanks to Venkat Kapil the issue got fixed.

Thanks!

Michele Ceriotti

unread,
Aug 29, 2017, 5:15:49 PM8/29/17
to ipi-users
Ah! I see what was the problem. We got a bit sidetracked by the unrelated atomic_unit/atomic_units initial bug. OK, glad this got solved without even having to file a bug. 

venkat kapil

unread,
Aug 30, 2017, 2:26:58 AM8/30/17
to ipi-users
@Ceriotti: actually this went through the full process of filing a bug, opening a pull request, fixing it and closing the issue, just that it was a quick fix.
Thanks Nicolas for finding the bug. 
Reply all
Reply to author
Forward
0 new messages