diff --git a/python/lammps/core.py b/python/lammps/core.py index 05192b5f6e..9ea2530cdc 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -1795,20 +1795,38 @@ class lammps(object): # ------------------------------------------------------------------------- def fix_external_set_energy_global(self, fix_id, eng): - """Get access to that array with per-atom forces of a fix external instance with a given fix ID. + """Set the global energy contribution for a fix external instance with the given ID. - This is a wrapper around the :cpp:func:`lammps_fix_external_get_force` function + This is a wrapper around the :cpp:func:`lammps_fix_external_set_energy_global` function of the C-library interface. :param fix_id: Fix-ID of a fix external instance :type: string - :param eng: potential energy to be added by fix external + :param eng: potential energy value to be added by fix external :type: float """ with ExceptionCheck(self): return self.lib.lammps_fix_external_set_energy_global(self.lmp, fix_id.encode(), eng) + # ------------------------------------------------------------------------- + + def fix_external_set_virial_global(self, fix_id, virial): + """Set the global virial contribution for a fix external instance with the given ID. + + This is a wrapper around the :cpp:func:`lammps_fix_external_set_virial_global` function + of the C-library interface. + + :param fix_id: Fix-ID of a fix external instance + :type: string + :param eng: list of 6 floating point numbers with the virial to be added by fix external + :type: float + """ + + cvirial = (6*c_double)(*virial) + with ExceptionCheck(self): + return self.lib.lammps_fix_external_set_virial_global(self.lmp, fix_id.encode(), cvirial) + # ------------------------------------------------------------------------- def fix_external_set_vector_length(self, fix_id, length): """Set the vector length for a global vector stored with fix external for analysis diff --git a/src/library.cpp b/src/library.cpp index 2c75657447..167c0c39b5 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -5103,7 +5103,7 @@ void lammps_fix_external_set_vector_length(void *handle, const char *id, int len END_CAPTURE } -/** Store global vector for a fix external instance with the given ID. +/** Store a global vector value for a fix external instance with the given ID. \verbatim embed:rst diff --git a/unittest/python/python-fix-external.py b/unittest/python/python-fix-external.py index eab4687e2b..1b46943b5a 100644 --- a/unittest/python/python-fix-external.py +++ b/unittest/python/python-fix-external.py @@ -4,6 +4,8 @@ from lammps import lammps, LMP_STYLE_GLOBAL, LMP_TYPE_VECTOR # add timestep dependent force def callback_one(lmp, ntimestep, nlocal, tag, x, f): + virial = [1.0, 1.0, 1.0, 0.0, 0.0, 0.0] + lmp.fix_external_set_virial_global("ext",virial) for i in range(nlocal): f[i][0] = float(ntimestep) f[i][1] = float(ntimestep) @@ -49,6 +51,7 @@ class PythonExternal(unittest.TestCase): lmp.command("run 10 post no") self.assertAlmostEqual(lmp.get_thermo("temp"),1.0/30.0,14) self.assertAlmostEqual(lmp.get_thermo("pe"),1.0/8.0,14) + self.assertAlmostEqual(lmp.get_thermo("press"),0.15416666666666667,14) val = 0.0 for i in range(0,6): val += lmp.extract_fix("ext",LMP_STYLE_GLOBAL,LMP_TYPE_VECTOR,nrow=i)