Beispiel #1
0
 def test_set_radii(self):
     atom = Atom("H", [0, 0, 0])
     self.assertEqual(atom._radii, 0.32)
     atom = Atom("X", [0, 0, 0])  # ghost atom
     self.assertEqual(atom._radii, 0.0)
     with self.assertRaises(ValueError):
         atom = Atom("NotAnElement", [0, 0, 0])
     atom = Atom()
     atom.element = "NotAnElement"
     with self.assertLogs(logger=Atom.LOG, level="WARNING"):
         atom._set_radii()
Beispiel #2
0
    def test_store_atoms(self):
        atoms_read = self.read_xyz(TestAtoms.small_mol)
        atoms_manual = []
        mol = []
        with open(TestAtoms.small_mol) as f:
            # split xyz file into info matrix
            tmp = f.read()
            tmp = tmp.split("\n")
            for line in tmp:
                line = line.strip().split()
                if len(line):
                    mol += [line]
            # remove atom number and comment line
            mol = mol[2:]
        for i, line in enumerate(mol):
            a = Atom()
            a.element = line[0]
            a.coords = np.array(line[1:4], dtype=float)
            a.flag = False
            a.name = str(i + 1)
            a.tags = set([i])
            atoms_manual += [a]

        # test manual and **kwargs assignment match
        for a, b in zip(atoms_read, atoms_manual):
            self.assertEqual(a.element, b.element)
            self.assertTrue(np.linalg.norm(a.coords - b.coords) < 10**(-8))
            self.assertEqual(a.name, b.name)
            self.assertEqual(a.tags, b.tags)
            # should have automatic lookup of _radii
            self.assertTrue(a._radii is not None)

        # transform back into xyz format for verification
        atom_matrix = []
        for a in atoms_read:
            tmp = [str(a.element)]
            for c in a.coords:
                tmp += ["{:7.5f}".format(c)]
            atom_matrix += [tmp]
        for a, b in zip(mol, atom_matrix):
            a = ' '.join(a)
            b = ' '.join(b)
            self.assertEqual(a, b)

        return