Fix potential problem in Messenger related to MPI window
[hoomd-blue.git] / test / hoomd_script / test_init_read_xml.py
blobab1dcb935b6218acbb81241afa8b5d506ace745b
1 # -*- coding: iso-8859-1 -*-
2 # Maintainer: joaander
4 from hoomd_script import *
5 import unittest
6 import os
8 # unit tests for init.read_xml
9 class init_read_xml_tests (unittest.TestCase):
10 def setUp(self):
11 print
12 if (comm.get_rank()==0):
13 f = open("test.xml", "w");
14 f.write('''<?xml version="1.0" encoding="UTF-8"?>
15 <hoomd_xml version="1.0">
16 <configuration time_step="0">
17 <box lx="8" ly="8" lz="8"/>
18 <position>
19 -1 2 3
20 2 1 -3
21 3 -2 1
22 </position>
23 <type>
24 A B C
25 </type>
26 </configuration>
27 </hoomd_xml>
28 ''');
29 f = open("test_out_of_box.xml", "w");
30 f.write('''<?xml version="1.0" encoding="UTF-8"?>
31 <hoomd_xml version="1.0">
32 <configuration time_step="0">
33 <box lx="4" ly="4" lz="4"/>
34 <position>
35 -1 2 3
36 2 1 -3
37 3 -2 1
38 </position>
39 <type>
40 A B C
41 </type>
42 </configuration>
43 </hoomd_xml>
44 ''');
46 # tests basic creation of the random initializer
47 def test(self):
48 init.read_xml('test.xml');
49 self.assert_(globals.system_definition);
50 self.assert_(globals.system);
51 self.assertEqual(globals.system_definition.getParticleData().getNGlobal(), 3);
53 # tests creation with a few more arugments specified
54 def test_moreargs(self):
55 init.read_xml('test.xml', time_step=100);
56 self.assert_(globals.system_definition);
57 self.assert_(globals.system);
58 self.assertEqual(globals.system_definition.getParticleData().getNGlobal(), 3);
60 # tests creation with out of box particles
61 def test_out_of_box_1(self):
62 self.assertRaises(RuntimeError, init.read_xml, 'test_out_of_box.xml')
64 # tests creation with out of box particles
65 def test_out_of_box_2(self):
66 sys=init.read_xml('test_out_of_box.xml',wrap_coordinates=True)
67 self.assert_(globals.system_definition);
68 self.assert_(globals.system);
69 self.assertEqual(globals.system_definition.getParticleData().getNGlobal(), 3);
70 self.assertAlmostEqual(sys.particles[0].position[2],-1,5)
72 # checks for an error if initialized twice
73 def test_inittwice(self):
74 init.read_xml('test.xml');
75 self.assertRaises(RuntimeError, init.read_xml, 'test.xml');
77 def tearDown(self):
78 if (comm.get_rank()==0):
79 os.remove("test.xml");
80 os.remove("test_out_of_box.xml");
81 init.reset();
83 if __name__ == '__main__':
84 unittest.main(argv = ['test.py', '-v'])