diff --git a/README.rst b/README.rst index 2d38021b..339843f1 100644 --- a/README.rst +++ b/README.rst @@ -1,10 +1,10 @@ -The Atomistic Cookbook repository -================================= +Source code for the Atomistic Cookbook +====================================== .. image:: ./docs/src/_static/cookbook-icon.svg :alt: A cookbook with a cover showing a water molecule and mathematical symbols :align: center - :width: 50% + :width: 30% This repository contains the source code for a collection of software recipes, diff --git a/docs/src/software/chemiscope.sec b/docs/src/software/chemiscope.sec index 0cc376c1..a65ac95f 100644 --- a/docs/src/software/chemiscope.sec +++ b/docs/src/software/chemiscope.sec @@ -21,3 +21,4 @@ repository `_. - examples/water-model/water-model - examples/polarizability/polarizability - examples/pet-mad/pet-mad +- examples/pet-mad-nc/pet-mad-nc diff --git a/docs/src/software/i-pi.sec b/docs/src/software/i-pi.sec index 2b2f2684..d6d3b240 100644 --- a/docs/src/software/i-pi.sec +++ b/docs/src/software/i-pi.sec @@ -15,3 +15,4 @@ it on the `ipi-code website `_, the `documentation pages - examples/pi-mts-rpc/mts-rpc - examples/water-model/water-model - examples/pet-mad/pet-mad +- examples/pet-mad-nc/pet-mad-nc diff --git a/docs/src/software/metatensor.sec b/docs/src/software/metatensor.sec index 2ba22c2a..017ebca7 100644 --- a/docs/src/software/metatensor.sec +++ b/docs/src/software/metatensor.sec @@ -12,3 +12,4 @@ training and evaluating ML models. - examples/water-model/water-model - examples/polarizability/polarizability - examples/pet-mad/pet-mad +- examples/pet-mad-nc/pet-mad-nc diff --git a/examples/pet-mad-nc/README.rst b/examples/pet-mad-nc/README.rst new file mode 100644 index 00000000..ef7b8f95 --- /dev/null +++ b/examples/pet-mad-nc/README.rst @@ -0,0 +1,5 @@ +Non-conservative MTS MD +======================= + +An example of running hybrid conservative/non-conservative MD +using PET-MAD and i-PI. diff --git a/examples/pet-mad-nc/data/bmimcl.xyz b/examples/pet-mad-nc/data/bmimcl.xyz new file mode 100644 index 00000000..4f9cac77 --- /dev/null +++ b/examples/pet-mad-nc/data/bmimcl.xyz @@ -0,0 +1,418 @@ +416 +Lattice="16.264699935913086 0.0 0.0 0.0 16.264699935913086 0.0 0.0 0.0 16.264699935913086" Properties=species:S:1:pos:R:3 ipi_comment="Step: 3520 Bead: 0 positions{ase} cell{ase}" pbc="T T T" +N 10.54382941 5.58261047 8.38256391 +N 9.12539946 3.96644750 7.67972009 +C 9.89406517 4.45608192 8.71783024 +H 9.84036730 4.01558392 9.70058374 +C 10.16441039 5.91806183 7.12882157 +H 10.58897085 6.79814692 6.65632292 +C 9.35163402 4.88938055 6.66522323 +H 8.93317660 4.65496195 5.67880439 +C 8.56137026 2.67033583 7.58792333 +H 7.81587876 2.47477848 8.37551311 +H 9.40409166 1.93639532 7.57239244 +H 7.94094914 2.64187610 6.63885479 +C 11.14962304 6.42382001 9.35235562 +H 11.00371162 5.92878853 10.35090205 +H 10.55404119 7.34136305 9.37578952 +C 12.55425541 6.65545244 8.94978663 +H 12.67680910 7.25850310 8.05021326 +H 12.97838228 5.71205570 8.78992591 +C 13.54106145 7.15505869 10.04872616 +H 13.51360116 6.35028814 10.83810367 +H 14.50156065 7.23249669 9.54147743 +C 13.28884199 8.47623910 10.84188490 +H 14.02727630 8.52554678 11.66190904 +H 12.27889581 8.55121315 11.23965135 +H 13.40385181 9.26097346 10.11294326 +N 11.80530733 2.07148188 3.09162758 +N 11.76971650 0.97935483 1.21752516 +C 12.57701965 1.47040795 2.18408828 +H 13.62782866 1.27995751 2.25346475 +C 10.44231117 1.88145568 2.78531683 +H 9.72792329 2.29777004 3.43574212 +C 10.43714194 1.17206310 1.61960541 +H 9.73309028 0.51695874 1.01738402 +C 12.23260730 0.23837956 16.30269714 +H 12.55323863 0.84372145 15.48497109 +H 11.43873675 15.76451401 15.91397467 +H 13.04683263 -0.41309216 16.67302358 +C 12.23454968 2.56128373 4.36702095 +H 13.34213368 2.46848406 4.37448874 +H 11.93909829 1.83487554 5.17864452 +C 11.66415040 3.99308303 4.58167552 +H 12.00814291 4.28997804 5.57389549 +H 10.58665385 3.85012063 4.66487326 +C 12.19669364 4.97037736 3.52018885 +H 13.28272906 4.83654994 3.27416393 +H 11.71665182 4.79076335 2.56923751 +C 12.05063117 6.41961295 3.98148471 +H 12.34875714 7.22894515 3.27598750 +H 12.57548926 6.53270728 4.89116404 +H 10.99073790 6.68483948 4.26318442 +N 8.58550193 9.91630774 9.26986827 +N 6.77567933 10.18725756 8.01284102 +C 7.24086891 9.98127479 9.28027000 +H 6.65116943 10.10848918 10.18039455 +C 8.97688799 9.98905173 7.90701484 +H 9.99570807 9.90602595 7.49318596 +C 7.84905268 10.18200847 7.14826681 +H 7.61981296 10.36345878 6.12500681 +C 5.37998496 10.52952126 7.69268924 +H 4.78279221 9.65106904 7.42451410 +H 5.48600536 11.07943818 6.82376615 +H 4.91242024 10.98479751 8.60782348 +C 9.30751662 9.47417629 10.41025466 +H 10.38579472 9.62508878 10.15903679 +H 9.18800395 8.34544970 10.44323518 +C 8.91131414 10.11782965 11.73451590 +H 9.43433562 9.61360481 12.59645031 +H 7.83945142 9.89452561 11.91454962 +C 9.25936949 11.63040119 11.81915018 +H 9.98232861 12.05581554 11.11858746 +H 8.39576786 12.25886643 11.48001366 +C 9.70676074 12.03307512 13.27012596 +H 9.06565571 11.86417813 14.14638954 +H 9.95807191 13.06770624 13.25173154 +H 10.72971115 11.52956019 13.45856632 +N 10.59964518 11.50523577 2.80409465 +N 11.83991591 10.11172664 1.63823182 +C 11.49149302 10.48996995 2.90425960 +H 11.82257609 10.05548115 3.85862563 +C 10.44594306 11.81392057 1.44629584 +H 9.81347502 12.62541191 0.95563709 +C 11.23648002 10.92094036 0.72695186 +H 11.40323862 10.81911564 -0.34536901 +C 12.75220273 9.04480082 1.26260288 +H 12.00019572 8.21335924 1.15112479 +H 13.40444955 8.78728385 2.12365692 +H 13.18115876 9.28865706 0.28700009 +C 9.91922453 12.03118029 4.03970962 +H 10.54654447 11.70048444 4.94615013 +H 8.81770235 11.79721635 3.97093093 +C 10.02143159 13.49337750 3.91111517 +H 9.52529615 13.76122583 2.98671385 +H 11.10901382 13.76977736 3.72207441 +C 9.42126713 14.28506083 5.14618298 +H 8.32705122 14.01095233 5.21910928 +H 9.94108919 13.92799984 6.04156171 +C 9.42278558 15.85889592 4.97529911 +H 9.73866200 -0.21132027 3.90652876 +H 10.11928247 16.39075177 5.63906280 +H 8.50876239 0.05114375 5.23801699 +N 14.28099182 5.88092019 13.49982680 +N 15.51942073 7.27930170 14.48498132 +C 14.35455994 7.17100116 13.88899947 +H 13.53217211 7.94300277 13.79214583 +C 15.41673704 5.16114001 13.86466158 +H 15.39671028 4.02915909 13.97535086 +C 16.20011865 6.08240300 14.51804337 +H 0.91458510 6.14608070 14.92710642 +C -0.24527400 8.45659722 15.07708575 +H 16.12501451 8.37854569 16.14786726 +H 15.38080649 9.33160948 14.76972273 +H 0.78451938 8.62554389 14.65196452 +C 13.09173541 5.31777797 12.87528477 +H 13.34979986 4.90404703 11.89683239 +H 12.36537495 6.19386926 12.67308888 +C 12.50832764 4.22075580 13.77357284 +H 13.12552116 3.38861380 13.55783063 +H 11.48896572 3.95011253 13.35266978 +C 12.34784688 4.53340226 15.24096621 +H 12.18540330 3.57357654 -0.47836072 +H 13.29513899 4.87087661 -0.59294882 +C 11.19263058 5.49126775 -0.68676435 +H 11.21581223 6.48863167 15.28935945 +H 10.94341317 5.48769708 0.38277978 +H 10.31906284 5.11636594 15.05683975 +N 2.10755201 12.50132905 5.24274466 +N 2.23944742 14.03444817 3.76939199 +C 2.74374963 12.87213915 4.08135941 +H 3.69439871 12.42050029 3.69973311 +C 1.19926890 13.43602992 5.61914647 +H 0.43501454 13.25118242 6.47771747 +C 1.22638399 14.40762618 4.65019007 +H 0.86951052 15.45815730 4.57871571 +C 2.73777947 14.84083885 2.60501186 +H 2.17017647 14.76957137 1.68705381 +H 3.72291395 14.45861207 2.36949299 +H 2.74056739 15.97350095 2.79757508 +C 2.48246431 11.26845199 5.92993157 +H 3.46076640 11.47183054 6.31154615 +H 2.60777910 10.50601207 5.14899034 +C 1.60224809 10.74693048 7.00314499 +H 1.34345769 11.46022588 7.81387802 +H 2.08405482 9.86668691 7.44123929 +C 0.28101493 10.33267729 6.39980955 +H 16.21859416 11.16905016 5.64343286 +H 0.51559659 9.36209875 5.87589380 +C -0.79185298 10.15161042 7.47512453 +H 15.37330043 11.03214732 8.10973618 +H -0.44321167 9.29594071 8.20059782 +H 14.52154901 9.79910743 7.05877563 +N 5.30691438 6.94956747 11.94071143 +N 5.53637858 5.90911678 10.14022775 +C 6.07308985 6.09641938 11.34145559 +H 7.04920901 5.67003227 11.64854720 +C 4.19692195 7.24474271 11.22508395 +H 3.40956623 7.87123355 11.63125521 +C 4.33383684 6.60743182 10.01984834 +H 3.71905144 6.56292850 9.11352700 +C 6.17412983 4.87033999 9.33954515 +H 5.83231953 3.83520214 9.33294330 +H 7.21668501 4.78344052 9.73720885 +H 6.24141484 5.07480953 8.22436495 +C 5.69667452 7.65849861 13.22497705 +H 4.96220078 7.24175417 14.02923079 +H 5.33681929 8.68306706 12.99650781 +C 7.20332663 7.72574851 13.46557213 +H 7.58692931 8.12269348 12.47764388 +H 7.77073082 6.71391415 13.72691232 +C 7.49125356 8.84712810 14.53330273 +H 7.27010649 9.84936647 14.12114896 +H 6.72907276 8.62264630 -0.86808629 +C 8.84745094 8.80240558 15.14470962 +H 9.03756413 7.81688344 -0.64521387 +H 9.06526191 9.51888594 15.95436425 +H 9.57395367 8.80346615 -1.94277017 +N 6.38163011 0.66950957 2.06173040 +N 5.84380541 -0.36446680 3.84736699 +C 5.78889347 0.79314434 3.19278560 +H 4.94901341 1.44874010 3.54553527 +C 6.96049568 15.66963075 1.92973957 +H 7.78984806 15.57802202 1.13196444 +C 6.64031800 15.01849600 3.07449918 +H 6.76247621 13.96390703 3.34408582 +C 5.15676657 -0.63192232 5.06889850 +H 4.05634778 -0.41151017 4.93999426 +H 5.66692133 -0.18719951 5.93079889 +H 5.24674721 14.51952830 5.36362949 +C 6.49449045 1.77277509 1.11033329 +H 6.36536532 1.33975713 0.09438745 +H 7.56887261 2.03151324 1.12182468 +C 5.54564665 2.95098286 1.33290168 +H 5.83498184 3.43906476 2.31514629 +H 4.48077939 2.53221040 1.33113952 +C 5.72763661 3.86641758 16.41542991 +H 5.33518582 3.43934610 15.52168352 +H 5.14011371 4.74629393 16.56865576 +C 7.16312767 4.38837427 16.13833604 +H 7.55239820 5.01544529 0.75122614 +H 7.16806260 5.14229647 15.33379687 +H 7.93678799 3.62516406 -0.33131097 +N 15.30979463 12.91489254 12.49328422 +N 14.43553475 13.77663048 14.25407713 +C 14.45870700 12.67141437 13.50193083 +H 13.93771334 11.72037292 13.68893823 +C -0.46021829 14.18068813 12.61197544 +H 0.24075623 14.56326953 11.77113235 +C 15.18883560 14.80483972 13.61537339 +H 15.28895523 15.86571541 13.89753416 +C 13.43057196 13.79861803 15.28733384 +H 13.81987479 14.27486374 16.21605210 +H 13.14026005 12.77007506 15.56503489 +H 12.51214792 14.28158143 14.88423967 +C -0.40132131 11.88253611 11.61896438 +H -0.05728790 12.37566370 10.66725695 +H 15.04936491 11.08412571 11.46772240 +C 0.87576272 11.19344721 12.34250670 +H 0.49474513 10.72834602 13.23736548 +H 1.55708896 11.92041720 12.79032826 +C 1.60883249 10.24833127 11.33518515 +H 1.52208505 10.88551692 10.35092421 +H 2.73317774 10.26626648 11.50203379 +C 0.85906449 8.99102821 11.12002964 +H 0.74871702 8.44872027 12.10066654 +H 1.41019136 8.32623452 10.44482374 +H -0.17786502 9.11434014 10.64498576 +N 1.58488569 2.46043313 8.95848790 +N 16.19336126 1.06658467 9.20877806 +C 16.63802508 2.30784826 9.48564634 +H 16.10351315 3.03335719 10.18817511 +C 1.85692168 1.34610058 8.13050110 +H 2.79645586 1.21452891 7.62487760 +C 0.75402356 0.51304223 8.24831732 +H 0.65199739 15.70144706 8.05719398 +C 14.98845575 0.55319762 9.92218023 +H 15.09797725 15.67306558 9.94511861 +H 14.03164054 0.74739851 9.36454441 +H 14.94658331 0.93493459 10.89805811 +C 2.40050603 3.61600593 8.93998433 +H 3.44659611 3.27958043 8.71724527 +H 2.41125183 4.08180147 9.93029950 +C 2.10321140 4.62290948 7.88829902 +H 1.83581614 4.09899485 6.91772861 +H 3.07447913 5.22908391 7.64460423 +C 17.08292240 5.40358296 8.25892445 +H 16.83549064 5.00428086 9.26938270 +H 17.41827969 6.46458736 8.40971375 +C 15.89060059 5.22770133 7.33904195 +H 16.23092545 5.30249594 6.21332758 +H 15.13293330 5.94382235 7.55060633 +H 15.44574811 4.23360195 7.54355000 +N 16.64913223 4.02501126 1.71766034 +N 0.71782007 2.05817631 0.87983590 +C 0.94891231 3.38161549 0.68075160 +H 1.57427646 3.88104692 16.22773008 +C 15.88058565 3.09587875 2.46750876 +H 15.43018656 3.41265220 3.40521710 +C 16.08222222 1.83936033 1.92220610 +H 15.79844368 0.82037048 2.27691617 +C 1.11280310 0.97653469 16.22960137 +H 1.02434785 0.00586355 0.46798560 +H 2.14103695 1.05159293 15.90943264 +H 0.54576539 0.95863112 15.28482059 +C 16.64391635 5.42728648 2.04626028 +H 15.74696430 5.91087678 1.65493415 +H 1.32221093 5.87928968 1.67345377 +C 16.62975418 5.58909559 3.56186480 +H 1.13572675 4.97002847 4.02067696 +H 15.74802420 5.21906736 4.10483172 +C 0.50375775 7.10019365 3.98813857 +H 0.87593323 7.20127049 5.05885178 +H 1.34027787 7.44487909 3.46494137 +C 15.50321751 7.85305525 3.74592890 +H 14.56537771 7.39022090 4.16175872 +H 15.27062451 8.09388440 2.71544128 +H 15.57358570 8.87694286 4.20549064 +N 13.22113613 13.19141803 7.15255537 +N 13.97057756 14.96875827 6.14988167 +C 13.37626979 14.50701031 7.28719475 +H 13.10871151 15.08959079 8.10991946 +C 13.67937902 12.81831932 5.90060409 +H 13.77915872 11.75491176 5.70402689 +C 14.09903999 13.94876391 5.30862488 +H 14.59371290 14.00712618 4.34627302 +C 14.48046611 16.35241955 5.92331632 +H 13.82750415 0.76567809 6.49134153 +H 14.44329560 16.45124860 4.87582954 +H 15.52089025 0.29814859 6.31907840 +C 12.75305120 12.25367609 8.23185714 +H 13.44174594 12.20789063 9.15735925 +H 12.74806750 11.22886525 7.78414700 +C 11.42583128 12.50520071 8.79291553 +H 11.25061831 11.72478130 9.55295027 +H 10.65448519 12.54313827 8.06006095 +C 11.30363993 13.86644782 9.61706059 +H 11.34150098 14.79596794 8.94242383 +H 10.31855608 13.88989840 10.00153445 +C 12.32165187 13.94632312 10.78512116 +H 11.99207965 13.32231222 11.61319228 +H 12.51636039 14.90068076 11.14605234 +H 13.27329914 13.59205762 10.41302443 +N 4.51749669 6.63760114 4.22393201 +N 4.50880895 4.65130818 5.09549175 +C 4.86032904 5.93588764 5.28837863 +H 5.36538147 6.32149033 6.14741834 +C 3.89531609 5.82864003 3.35242831 +H 3.58786862 6.25008784 2.35682135 +C 3.91851410 4.53883619 3.89761464 +H 3.50247884 3.59478961 3.53765069 +C 4.69826112 3.45028080 5.97311764 +H 4.22128221 3.82520610 6.90691323 +H 5.78323917 3.25314939 6.12180070 +H 4.09597854 2.61059045 5.56882763 +C 4.96168119 8.00354928 4.03413197 +H 4.93469865 8.49181383 5.03155056 +H 4.18439308 8.51183656 3.42014447 +C 6.22286812 8.03634248 3.16810505 +H 6.51764275 9.05534850 3.10829599 +H 5.83739948 7.73668119 2.15759827 +C 7.34860565 7.12729094 3.53312087 +H 7.60969981 7.24859470 4.56414604 +H 6.95475368 6.12635663 3.30529456 +C 8.56239857 7.44022635 2.64400272 +H 8.89861374 8.53336166 2.79932626 +H 8.19787134 7.48544121 1.60422170 +H 9.40071383 6.72984452 2.65038795 +N 4.54799454 11.03304159 16.49161783 +N 5.94762743 12.29384400 15.30556390 +C 4.91378427 11.42218563 15.21644933 +H 4.37833595 11.14248619 14.32145681 +C 5.37053479 11.64812209 1.10756408 +H 5.48719208 11.42703098 2.26172695 +C 6.19017177 12.42230263 16.63047696 +H 6.92079206 13.16285900 0.69572545 +C 6.37644751 13.17063824 14.16461065 +H 5.68136741 13.99199731 14.39902398 +H 6.09626854 12.61685989 13.21461570 +H 7.42457236 13.36935935 14.16979523 +C 3.73198024 9.87077805 16.63393397 +H 4.19750984 9.04234431 0.98382337 +H 3.57658851 9.47877167 15.60406196 +C 2.43078119 10.27482104 1.06605438 +H 2.86196523 10.88826593 1.92463096 +H 1.97178280 9.33454981 1.36963604 +C 1.48545488 11.18495379 16.60762598 +H 2.15945394 12.04649696 16.42003893 +H 1.28156868 10.64318678 15.67720789 +C 0.16898812 11.47298737 1.14298769 +H 0.42588046 11.79252282 2.14788604 +H 15.86859329 10.54737202 1.25316338 +H -0.45757343 12.31347416 17.03879905 +N 8.50838255 0.83712310 12.38799605 +N 10.27872519 1.58884250 11.43014479 +C 9.56733548 1.64322210 12.56533080 +H 9.93980589 2.34269630 13.27790877 +C 8.62812413 0.12389090 11.19269542 +H 7.91843324 -0.61163237 10.88858428 +C 9.73162075 0.63736894 10.62448968 +H 10.27815349 0.32048126 9.77927007 +C 11.67249230 2.16884619 11.20992185 +H 12.01192392 1.64785994 10.32377421 +H 12.34639777 2.03809987 12.03771836 +H 11.55299168 3.24268287 11.00939885 +C 7.50050910 0.71954455 13.39152302 +H 7.90055197 1.03912201 14.42564105 +H 7.16002331 -0.37453004 13.37741757 +C 6.30877734 1.56876441 12.89204654 +H 5.52326473 1.08789887 13.53015060 +H 6.10380156 1.42371346 11.84852822 +C 6.42382553 3.03878142 13.11740520 +H 6.61767014 3.30295534 14.14170196 +H 7.28994549 3.47200545 12.51260034 +C 5.00613864 3.56577689 12.75067490 +H 4.39874183 2.96133488 13.35858405 +H 4.72433209 3.32986819 11.76678909 +H 4.78665667 4.61018281 13.03853249 +N 3.38630729 14.29151017 10.30693293 +N 2.95597712 15.85126596 11.72899269 +C 3.12326278 15.59704609 10.46878779 +H 3.17027368 16.32081827 9.65787415 +C 3.44515050 13.66308927 11.54057736 +H 3.84306839 12.55388633 11.69269703 +C 3.12746394 14.66040693 12.43343714 +H 3.09727520 14.70474661 13.52673052 +C 2.64276703 17.13371983 12.36547943 +H 3.43820683 1.56910203 12.03917725 +H 2.60646812 17.06518765 13.48356646 +H 1.63951806 17.50422765 12.08863393 +C 3.55281322 13.57158007 9.08311187 +H 2.53293222 13.62973294 8.65041613 +H 3.77090935 12.49989009 9.46137054 +C 4.80478422 14.05814955 8.38670717 +H 4.77330642 15.04031423 7.95767419 +H 4.87755447 13.31292215 7.49322499 +C 6.00705979 13.97859426 9.22413504 +H 5.99637319 14.89821969 9.89045787 +H 6.02968892 13.00434772 9.77170813 +C 7.23043460 14.06231315 8.26780021 +H 7.26081696 13.17527131 7.52912992 +H 8.18072030 13.95365519 8.84770439 +H 7.37622041 15.03239512 7.64938829 +Cl 5.13370073 10.75621106 11.51548775 +Cl 11.94148135 1.10542372 7.77368605 +Cl 3.44799241 7.59993308 7.21095887 +Cl 3.09881117 6.53436764 16.25222419 +Cl 15.31621175 1.77697844 13.00292956 +Cl 9.01611983 14.81708868 15.66383512 +Cl 14.41068572 15.27596409 2.36523325 +Cl 3.99977527 15.43812622 15.54740244 +Cl 5.81819629 11.74327931 4.63789175 +Cl -0.16569567 13.60082384 8.89581699 +Cl 5.29462168 1.44826053 8.93933837 +Cl 12.04263846 9.30629751 6.28014657 +Cl 9.26080762 4.79045027 11.92254612 +Cl 2.42797028 1.60033738 3.97291870 +Cl 7.63968749 3.01046094 4.37261577 +Cl 12.72859021 10.04258683 14.15045022 diff --git a/examples/pet-mad-nc/data/input-nc-nve-mts.xml b/examples/pet-mad-nc/data/input-nc-nve-mts.xml new file mode 100644 index 00000000..ea6a9444 --- /dev/null +++ b/examples/pet-mad-nc/data/input-nc-nve-mts.xml @@ -0,0 +1,45 @@ + + + + [step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, + kinetic_md{electronvolt}, potential{electronvolt}, + pot_component(0){electronvolt}, pot_component(1){electronvolt} + ] + + positions + forces_component(0) + forces_component(1) + + +50 +12345 + + + metatensor + {template:data/bmimcl.xyz,model:pet-mad-latest.pt,device:cpu,non_conservative:False} + + + metatensor + {template:data/bmimcl.xyz,model:pet-mad-latest.pt,device:cpu,non_conservative:True} + + + + data/bmimcl.xyz + 400.0 + + + + [1,0] + + + [-1,1] + + + + + 4 + [1,4] + + + + diff --git a/examples/pet-mad-nc/data/input-nc-nve.xml b/examples/pet-mad-nc/data/input-nc-nve.xml new file mode 100644 index 00000000..64ff3bea --- /dev/null +++ b/examples/pet-mad-nc/data/input-nc-nve.xml @@ -0,0 +1,36 @@ + + + + [step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, + kinetic_md{electronvolt}, potential{electronvolt}, + pot_component(0){electronvolt} + ] + + positions + forces_component(0) + + +200 +12345 + + metatensor + {template:data/bmimcl.xyz,model:pet-mad-latest.pt,device:cpu,non_conservative:True} + + + + data/bmimcl.xyz + 400.0 + + + + + + + + + 1 + + + + + diff --git a/examples/pet-mad-nc/data/input-nve.xml b/examples/pet-mad-nc/data/input-nve.xml new file mode 100644 index 00000000..5cbe38e2 --- /dev/null +++ b/examples/pet-mad-nc/data/input-nve.xml @@ -0,0 +1,36 @@ + + + + [step, time{picosecond}, conserved{electronvolt}, temperature{kelvin}, + kinetic_md{electronvolt}, potential{electronvolt}, + pot_component(0){electronvolt} + ] + + positions + forces_component(0) + + +32 +12345 + + metatensor + {template:data/bmimcl.xyz,model:pet-mad-latest.pt,device:cpu,non_conservative:False} + + + + data/bmimcl.xyz + 400.0 + + + + + + + + + 1 + + + + + diff --git a/examples/pet-mad-nc/environment.yml b/examples/pet-mad-nc/environment.yml new file mode 100644 index 00000000..b31741d7 --- /dev/null +++ b/examples/pet-mad-nc/environment.yml @@ -0,0 +1,13 @@ +channels: + - metatensor + - conda-forge +dependencies: + - python=3.12 + - pip + - pip: + - ase>=3.23 + - pet-mad>=1.1.0rc4,<2.0 + - ipi>=3.1.3,<4.0 + - chemiscope>=0.8.5,<0.9 + - matplotlib>=3.10,<4.0 + - vesin[torch]>=0.3.2,<0.4 diff --git a/examples/pet-mad-nc/pet-mad-nc.py b/examples/pet-mad-nc/pet-mad-nc.py new file mode 100644 index 00000000..d8965115 --- /dev/null +++ b/examples/pet-mad-nc/pet-mad-nc.py @@ -0,0 +1,228 @@ +""" +Using non-conservative forces with PET-MAD +=========================================== + +:Authors: Michele Ceriotti `@ceriottm `_, + Filippo Bigi `@frostedoyster `_ + +PET-MAD is introduced, and benchmarked for several challenging modeling tasks, +in `this preprint `_. To get a first taste +of PET-MAD, for basic tasks such as geometry optimization and conservative +MD, see also +`this recipe `_. +""" + +# %% +# +# If you don't want to use the conda environment for this recipe, +# you can get all dependencies installing +# the `PET-MAD package `_: +# +# .. code-block:: bash +# +# pip install git+https://github.com/lab-cosmo/pet-mad.git +# + +import ase.io + +# i-PI scripting utilities +import chemiscope +import matplotlib.pyplot as plt +import metatensor.torch.atomistic as mta + +# import numpy as np +# import requests +from ipi.utils.parsing import read_output, read_trajectory +from ipi.utils.scripting import InteractiveSimulation + +# pet-mad ASE calculator +from pet_mad.calculator import PETMADCalculator + + +# from copy import copy, deepcopy + + +if hasattr(__import__("builtins"), "get_ipython"): + get_ipython().run_line_magic("matplotlib", "inline") # noqa: F821 + + +# %% +# Fetch PET-MAD and export the model +# ---------------------------------- + +calculator = PETMADCalculator(version="latest", device="cpu") + +# %% +# +# The model can also be exported in a format that can be used with +# external MD engines. This is done by saving the model to a file, +# which includes the model architecture and weights. + +calculator.model.save("pet-mad-latest.pt") + + +# %% +# +# Non-conservative forces +# ----------------------- +# +# Interatomic potentials are typically used to compute the forces acting +# on the atoms by differentiating with respect to atomic positions, i.e. if +# +# .. math :: +# +# V(\mathbf{r}_1, \mathbf{r}_2, \ldots \mathbf{r}_n) +# +# is the potential for an atomic configuration then the force acting on +# atom :math:`i` is +# +# .. math :: +# +# \mathbf{f}_i = \partial V/\partial \mathbf{r}_i +# +# Even though the early ML-based interatomic potentials followed this route, +# .... blah blah and intro to be filled. Reference to our paper. + +structure = ase.io.read("data/bmimcl.xyz") + +structure.calc = calculator +energy_c = structure.get_potential_energy() +forces_c = structure.get_forces() + +calculator_nc = mta.ase_calculator.MetatensorCalculator( + calculator.model, device="cpu", non_conservative=True +) + +structure.calc = calculator_nc +energy_nc = structure.get_potential_energy() +# forces_nc = structure.get_forces() + +# %% + +print(f"Energy:\n Conservative: {energy_c:.8}\n Non-conserv.: {energy_nc:.8}") + +# %% +# +# Constant-energy molecular dynamics without energy conservation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# +# Some more blah blah. Explain the system (melting of Ni) + +# %% +# We use an `XML` input file that instructs ``i-PI`` to perform a constant- +# energy dynamics. The ``non_conservative:True`` option requires the model +# to predict forces using a dedicated direct head, rather than backpropagation. + +with open("data/input-nc-nve.xml", "r") as file: + input_nve = file.read() +print(input_nve) + +# %% +# This input file uses a ```` block to run the metatensor PES +# as a library -- it is also possible to use a socket interface that is useful +# for parallelizing over multiple evaluators, see e.g. +# `this recipe +# `_. +# ``i-PI`` can be run as a stand-alone command +# +# .. code-block:: bash +# +# i-pi data/input-nc-nve.xml > log +# +# but here we use the Python API to integrate it in the notebook. + +sim = InteractiveSimulation(input_nve) +sim.run(200) + +# %% +# +# The simulation generates output files that can be parsed and visualized from Python. + +data, info = read_output("nve-nc.out") +trj = read_trajectory("nve-nc.pos_0.extxyz") + +fig, ax = plt.subplots(1, 1, figsize=(4, 3), constrained_layout=True) + +ax.set_facecolor("white") +ax.plot(data["time"], data["potential"], "b-", label="potential") +ax.plot(data["time"], data["conserved"] - 20, "k-", label="conserved") +ax.set_xlabel("t / ps") +ax.set_ylabel("energy / ev") +ax.legend() + +# %% +# +# The trajectory (which is started from oxygen molecules placed on top of the surface) +# shows quick relaxation to an oxide layer. If you look carefully, you'll also see that +# Mg and Si atoms tend to cluster together, and accumulate at the surface. + +chemiscope.show( + frames=trj, + properties={ + "time": data["time"][::2], + "potential": data["potential"][::2], + "temperature": data["temperature"][::2], + }, + mode="default", + settings=chemiscope.quick_settings( + map_settings={ + "x": {"property": "time", "scale": "linear"}, + "y": {"property": "potential", "scale": "linear"}, + }, + structure_settings={ + "unitCell": True, + }, + trajectory=True, + ), +) + + +# %% +# +# Energy conservation at low-cost with multiple time stepping +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# +# Some more blah blah. + +# %% +# We use an `XML` input file that instructs ``i-PI`` to perform a constant- +# energy dynamics. The ``non_conservative:True`` option requires the model +# to predict forces using a dedicated direct head, rather than backpropagation. + +with open("data/input-nc-nve-mts.xml", "r") as file: + input_nve_mts = file.read() +print(input_nve_mts) + +# %% +# This input file uses a ```` block to run the metatensor PES +# as a library -- it is also possible to use a socket interface that is useful +# for parallelizing over multiple evaluators, see e.g. +# `this recipe +# `_. +# ``i-PI`` can be run as a stand-alone command +# +# .. code-block:: bash +# +# i-pi data/input-nc-nve-mts.xml > log +# +# but here we use the Python API to integrate it in the notebook. + +sim = InteractiveSimulation(input_nve_mts) +sim.run(50) + +# %% + +data_mts, info = read_output("nve-nc-mts.out") +trj_mts = read_trajectory("nve-nc-mts.pos_0.extxyz") + +fig, ax = plt.subplots(1, 1, figsize=(4, 3), constrained_layout=True) + +ax.set_facecolor("white") +ax.plot(data["time"], data["potential"], "b-", label="potential") +ax.plot(data["time"], data["conserved"] - 20, "k-", label="conserved") +ax.plot(data_mts["time"], data_mts["conserved"] - 20, "r-", label="conserved") +ax.plot(data_mts["time"], data_mts["potential"] - 20, "r-", label="conserved") +ax.set_xlabel("t / ps") +ax.set_ylabel("energy / ev") +ax.legend() +# %% diff --git a/examples/pet-mad/data/al6xxx-o2.in b/examples/pet-mad/data/al6xxx-o2.in index 0de51b44..3f99b9f8 100644 --- a/examples/pet-mad/data/al6xxx-o2.in +++ b/examples/pet-mad/data/al6xxx-o2.in @@ -19,5 +19,5 @@ fix 1 all nvt temp 800 800 0.10 # fix 2 all atom/swap 1 1 12345 800 types 1 2 # fix 2 all atom/swap 1 1 12345 800 types 1 3 # fix 2 all atom/swap 1 1 12345 800 types 1 4 -run 100 +run 80 diff --git a/examples/pet-mad/data/al6xxx-o2.xyz b/examples/pet-mad/data/al6xxx-o2.xyz index 9791b9ed..ba9543c3 100644 --- a/examples/pet-mad/data/al6xxx-o2.xyz +++ b/examples/pet-mad/data/al6xxx-o2.xyz @@ -1,55 +1,5 @@ -241 +191 Lattice="14.318912319027588 0.0 0.0 7.159456159513794 12.400541822839838 0.0 0.0 0.0 38.70614872174387" Properties=species:S:1:pos:R:3:tags:I:1 pbc="T T T" -Mg 1.43189123 0.82670279 10.00000000 9 -Al 4.29567370 0.82670279 10.00000000 9 -Al 7.15945616 0.82670279 10.00000000 9 -Al 10.02323862 0.82670279 10.00000000 9 -Si 12.88702109 0.82670279 10.00000000 9 -Al 2.86378246 3.30681115 10.00000000 9 -Al 5.72756493 3.30681115 10.00000000 9 -Al 8.59134739 3.30681115 10.00000000 9 -Al 11.45512986 3.30681115 10.00000000 9 -Al 14.31891232 3.30681115 10.00000000 9 -Mg 4.29567370 5.78691952 10.00000000 9 -Al 7.15945616 5.78691952 10.00000000 9 -Al 10.02323862 5.78691952 10.00000000 9 -Al 12.88702109 5.78691952 10.00000000 9 -Al 15.75080355 5.78691952 10.00000000 9 -Al 5.72756493 8.26702788 10.00000000 9 -Al 8.59134739 8.26702788 10.00000000 9 -Al 11.45512986 8.26702788 10.00000000 9 -Al 14.31891232 8.26702788 10.00000000 9 -Al 17.18269478 8.26702788 10.00000000 9 -Al 7.15945616 10.74713625 10.00000000 9 -Al 10.02323862 10.74713625 10.00000000 9 -Si 12.88702109 10.74713625 10.00000000 9 -Al 15.75080355 10.74713625 10.00000000 9 -Al 18.61458601 10.74713625 10.00000000 9 -Al -0.00000000 1.65340558 12.33826859 8 -Al 2.86378246 1.65340558 12.33826859 8 -Al 5.72756493 1.65340558 12.33826859 8 -Al 8.59134739 1.65340558 12.33826859 8 -Al 11.45512986 1.65340558 12.33826859 8 -Al 1.43189123 4.13351394 12.33826859 8 -Al 4.29567370 4.13351394 12.33826859 8 -Al 7.15945616 4.13351394 12.33826859 8 -Al 10.02323862 4.13351394 12.33826859 8 -Si 12.88702109 4.13351394 12.33826859 8 -Al 2.86378246 6.61362231 12.33826859 8 -Al 5.72756493 6.61362231 12.33826859 8 -Al 8.59134739 6.61362231 12.33826859 8 -Al 11.45512986 6.61362231 12.33826859 8 -Al 14.31891232 6.61362231 12.33826859 8 -Al 4.29567370 9.09373067 12.33826859 8 -Al 7.15945616 9.09373067 12.33826859 8 -Al 10.02323862 9.09373067 12.33826859 8 -Al 12.88702109 9.09373067 12.33826859 8 -Al 15.75080355 9.09373067 12.33826859 8 -Al 5.72756493 11.57383903 12.33826859 8 -Al 8.59134739 11.57383903 12.33826859 8 -Al 11.45512986 11.57383903 12.33826859 8 -Al 14.31891232 11.57383903 12.33826859 8 -Al 17.18269478 11.57383903 12.33826859 8 Mg 0.00000000 0.00000000 14.67653718 7 Al 2.86378246 0.00000000 14.67653718 7 Al 5.72756493 0.00000000 14.67653718 7 diff --git a/examples/pet-mad/data/model_c.pt b/examples/pet-mad/data/model_c.pt new file mode 100644 index 00000000..af0d40db Binary files /dev/null and b/examples/pet-mad/data/model_c.pt differ diff --git a/examples/pet-mad/data/model_nc.pt b/examples/pet-mad/data/model_nc.pt new file mode 100644 index 00000000..5f95c194 Binary files /dev/null and b/examples/pet-mad/data/model_nc.pt differ diff --git a/examples/pet-mad/data/nickel.xyz b/examples/pet-mad/data/nickel.xyz new file mode 100644 index 00000000..f2670378 --- /dev/null +++ b/examples/pet-mad/data/nickel.xyz @@ -0,0 +1,34 @@ +32 +Lattice="7.199999999999999 0.0 0.0 0.0 7.199999999999999 0.0 0.0 0.0 7.199999999999999" Properties=species:S:1:pos:R:3 ipi_comment="Step: 100 Bead: 0 positions{ase} cell{ase}" pbc="T T T" +Al -1.85390496 -0.95982674 1.97725575 +Al 2.86261250 3.15898022 0.57331454 +Al -0.72359428 -2.62713427 3.64623439 +Al 4.29563893 1.35474805 1.94203711 +Al -2.25383976 -0.51040542 6.71325518 +Al 1.03395315 1.04071714 4.46807275 +Al 0.93046776 1.41776842 6.93069925 +Al 3.21332631 3.13251253 3.29654208 +Ni 0.43653416 4.39201704 -1.17541302 +Ni 2.44317928 5.24507411 1.92192439 +Ni 6.13922636 4.31067580 0.27870937 +Ni 2.99738146 7.79472421 -2.94107677 +Ni 0.63257689 2.93422124 3.65847686 +Ni -0.13903928 6.59208609 5.59856458 +Ni 4.44853393 2.13439743 5.58726078 +Ni 0.65202417 6.46319053 2.95105454 +Ni 3.07880245 1.28266141 0.24123238 +Ni 5.68508963 0.67317343 4.71454935 +Ni 6.68773449 1.01636173 2.31489816 +Ni 5.48738394 2.67065291 -3.56673154 +Ni 3.63945425 -2.52245666 6.19962471 +Ni 4.65160368 -1.38381038 4.32521624 +Ni -0.29530481 -0.78118178 7.51117915 +Ni 4.61973821 4.24619744 1.92444695 +Ni 5.65027402 1.51590226 0.28430981 +Ni 2.03466520 8.19169094 2.14800988 +Ni 7.89866872 3.76495004 0.87094364 +Ni 2.67420027 6.89868302 -1.07012589 +Ni 1.83831272 4.94538488 4.39742971 +Ni 1.99506120 2.57229298 5.48248905 +Ni 5.48763500 3.91153783 5.57536938 +Ni 3.44996386 6.80436847 2.68806868 diff --git a/examples/pet-mad/environment.yml b/examples/pet-mad/environment.yml index 8b456cc9..f17c1309 100644 --- a/examples/pet-mad/environment.yml +++ b/examples/pet-mad/environment.yml @@ -8,6 +8,6 @@ dependencies: - pip - pip: - ase - - ipi>=3.1.2 + - ipi==3.1.2 - chemiscope>=0.8.4 - matplotlib diff --git a/examples/pet-mad/inputs/nickel.xyz b/examples/pet-mad/inputs/nickel.xyz new file mode 100644 index 00000000..ef3986a7 --- /dev/null +++ b/examples/pet-mad/inputs/nickel.xyz @@ -0,0 +1,34 @@ +32 +Lattice="7.2 0.0 0.0 0.0 7.2 0.0 0.0 0.0 7.2" Properties=species:S:1:pos:R:3 pbc="T T T" +Ni 0.04454187 0.15457874 0.12596108 +Ni 0.04370318 1.95000420 1.91184154 +Ni 1.83573509 0.12884331 1.91958398 +Ni 1.92303186 1.89265686 0.07165795 +Ni 0.19190924 0.04701160 3.61889659 +Ni 0.04116880 1.91517186 5.56317915 +Ni 1.91817295 0.03169102 5.58591245 +Ni 1.90862314 1.82490488 3.69025253 +Ni 0.16624021 3.78437918 0.07411722 +Ni 0.11502732 5.41155667 1.80895247 +Ni 1.88561487 3.68501992 1.91533902 +Ni 1.89092684 5.47334069 0.13616005 +Ni 0.13256096 3.78185764 3.77535577 +Ni 0.01409603 5.46866518 5.46642113 +Ni 1.97184883 3.60053345 5.44955058 +Ni 1.95063962 5.40970450 3.62949639 +Ni 3.61636855 0.00654232 0.19947714 +Ni 3.76729948 1.93207137 1.83696219 +Ni 5.47783206 0.09663835 1.87546754 +Ni 5.51789413 1.88532203 0.15452776 +Ni 3.66412964 0.13315923 3.68647837 +Ni 3.71818983 1.96085601 5.43543213 +Ni 5.54731704 0.16090601 5.59503045 +Ni 5.40527227 1.81865617 3.73525599 +Ni 3.77409855 3.77888268 0.04458552 +Ni 3.77575860 5.56995384 1.83599413 +Ni 5.49352058 3.71215650 1.92995287 +Ni 5.53270737 5.51022677 0.07537065 +Ni 3.60323764 3.73888965 3.76030754 +Ni 3.77150406 5.57225362 5.48239838 +Ni 5.48403719 3.68038819 5.43621244 +Ni 5.51535161 5.56333248 3.64169044 diff --git a/examples/pet-mad/pet-mad.py b/examples/pet-mad/pet-mad.py index 829f5dfb..55c17c9e 100644 --- a/examples/pet-mad/pet-mad.py +++ b/examples/pet-mad/pet-mad.py @@ -52,6 +52,9 @@ import ase.units import chemiscope import matplotlib.pyplot as plt + +# pet-mad ASE calculator +import metatensor.torch.atomistic as mta import numpy as np import requests from ase.optimize import LBFGS @@ -63,8 +66,6 @@ motion_nvt_xml, simulation_xml, ) - -# pet-mad ASE calculator from pet_mad.calculator import PETMADCalculator @@ -148,6 +149,14 @@ calculator.model.save("pet-mad-latest.pt") +# %% +# The model can also be loaded from this torchscript dump, which often +# speeds up calculation as it involves compilation, and is functionally +# equivalent unless you plan on fine-tuning, or otherwise modifying +# the model. + +calculator = mta.ase_calculator.MetatensorCalculator("pet-mad-latest.pt", device="cpu") + # %% # # Here, we run the computation on the CPU. If you have a CUDA GPU you can also set @@ -352,7 +361,7 @@ opt.attach(lambda: traj_energy.append(atoms.get_potential_energy())) # stop the optimization early to speed up the example -opt.run(fmax=0.001, steps=30) +opt.run(fmax=0.001, steps=20) # %% # @@ -403,6 +412,7 @@ {motion_nvt_xml(timestep=5.0 * ase.units.fs)} + 0.1 [ Al, Si, Mg, O] @@ -419,7 +429,7 @@ ), motion=motion_xml, temperature=800, - verbosity="low", + verbosity="high", prefix="nvt_atomxc", ) @@ -432,7 +442,7 @@ # execute separately ``i-PI`` and the ``metatensor`` driver. sim = InteractiveSimulation(input_xml) -sim.run(100) +sim.run(80) # %% # diff --git a/noxfile.py b/noxfile.py index ca3f00a5..4ebe1ec5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -105,7 +105,7 @@ def should_reinstall_dependencies(session, **metadata): with open(value) as fd: to_hash[key] = fd.read() else: - to_hash[key] = value + to_hash[key] = str(value) to_hash = json.dumps(to_hash).encode("utf8") sha1 = hashlib.sha1(to_hash).hexdigest() @@ -195,7 +195,7 @@ def get_example_metadata(rst_file): metadata["description"] = rst_description or "" metadata["html"] = html_description or "" metadata["thumbnail"] = thumbnail_file - metadata["ref"] = os.path.join(gallery_dir, example_name) + metadata["ref"] = str(os.path.join(gallery_dir, example_name)) return metadata