File: python-scatter-gather.py

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (90 lines) | stat: -rw-r--r-- 3,449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

import sys,os,unittest
from lammps import lammps

has_full=False
try:
    machine=None
    if 'LAMMPS_MACHINE_NAME' in os.environ:
        machine=os.environ['LAMMPS_MACHINE_NAME']
    lmp=lammps(name=machine)
    has_full = lmp.has_style("atom","full")
    lmp.close()
except:
    pass

class PythonGather(unittest.TestCase):

    def setUp(self):
        machine=None
        if 'LAMMPS_MACHINE_NAME' in os.environ:
            machine=os.environ['LAMMPS_MACHINE_NAME']
        self.lmp=lammps(name=machine,
                        cmdargs=['-nocite',
                                 '-log','none',
                                 '-echo','screen'])
        self.lmp.command('shell cd ' + os.environ['TEST_INPUT_DIR'])

    # clean up temporary files
    def tearDown(self):
        self.lmp.close()

    # bond data comparison
    def checkBond(self, vals, btype, batom1, batom2):
        if ((vals[1] == batom1 and vals[2] == batom2)
            or (vals[1] == batom2 and vals[2] == batom1)):
            self.assertEqual(vals[0], btype)
            return 1
        else:
            return 0

    ##############################
    @unittest.skipIf(not has_full, "Gather_bonds test")
    def testGatherBond_newton_on(self):
        """Test gather_bonds() with newton on"""
        self.lmp.command("newton on on")
        self.lmp.file("in.fourmol")
        self.lmp.command("run 0 post no")
        nbonds, bonds = self.lmp.gather_bonds()
        self.assertEqual(nbonds, 24)
        self.assertEqual(len(bonds), 3*24)
        count = 0;
        for i in range(0,nbonds):
            count += self.checkBond(bonds[3*i:3*i+3], 5, 1, 2)
            count += self.checkBond(bonds[3*i:3*i+3], 3, 1, 3)
            count += self.checkBond(bonds[3*i:3*i+3], 2, 3, 4)
            count += self.checkBond(bonds[3*i:3*i+3], 2, 3, 5)
            count += self.checkBond(bonds[3*i:3*i+3], 1, 6, 3)
            count += self.checkBond(bonds[3*i:3*i+3], 3, 6, 8)
            count += self.checkBond(bonds[3*i:3*i+3], 4, 6, 7)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 8, 9)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 27, 28)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 29, 27)
        self.assertEqual(count,10)

    @unittest.skipIf(not has_full, "Gather_bonds test")
    def testGatherBond_newton_off(self):
        """Test gather_bonds() with newton off"""
        self.lmp.command("newton off off")
        self.lmp.file("in.fourmol")
        self.lmp.command("run 0 post no")
        nbonds, bonds = self.lmp.gather_bonds()
        self.assertEqual(nbonds, 24)
        self.assertEqual(len(bonds), 3*24)
        count = 0;
        for i in range(0,nbonds):
            count += self.checkBond(bonds[3*i:3*i+3], 5, 1, 2)
            count += self.checkBond(bonds[3*i:3*i+3], 3, 1, 3)
            count += self.checkBond(bonds[3*i:3*i+3], 2, 3, 4)
            count += self.checkBond(bonds[3*i:3*i+3], 2, 3, 5)
            count += self.checkBond(bonds[3*i:3*i+3], 1, 3, 6)
            count += self.checkBond(bonds[3*i:3*i+3], 3, 6, 8)
            count += self.checkBond(bonds[3*i:3*i+3], 4, 6, 7)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 8, 9)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 27, 28)
            count += self.checkBond(bonds[3*i:3*i+3], 5, 27, 29)
        self.assertEqual(count,10)

##############################
if __name__ == "__main__":
    unittest.main()