Пример #1
0
    def test_arrays(self):

        a = Atoms('HCHC',
                  positions=[[i] * 3 for i in range(4)],
                  cell=[4] * 3,
                  pbc=[True] * 3)

        s = AtomSelection.from_element(a, 'C')
        s.set_array('testarr', [1, 2])

        self.assertTrue(all(s.subset(a).get_array('testarr') == [1, 2]))

        # Test that arrays are reordered
        a.set_array('testarr', np.array([1, 2, 3, 4]))

        s = AtomSelection(a, [2, 0])
        a2 = s.subset(a)

        self.assertTrue((a2.get_array('testarr') == np.array([3, 1])).all())

        # Cell indices test!
        s = AtomSelection(a, [0, 3])
        s.set_array('cell_indices', [[0, 0, 0], [-1, 0, 0]])
        a2 = s.subset(a, True)

        self.assertTrue(np.allclose(a2.get_positions()[-1], [-1, 3, 3]))
Пример #2
0
    def test_basic(self):

        # Create an Atoms object
        a = Atoms('HHH')

        # Try a valid selection
        s1 = AtomSelection(a, [0, 2])

        # Try an invalid one
        self.assertRaises(ValueError, AtomSelection, a, [0, 3])

        # Check validation
        self.assertTrue(s1.validate(a))

        # Now make a subset
        a_s = s1.subset(a)
        self.assertTrue(len(a_s) == 2)
Пример #3
0
# in fractional coordinates (scaled=True).

# NOTE: the plane is defined by the plane equation cohefficients.
# So for ax+by+cz+d = 0 we have [a,b,c,d]

nh3r = mirr(nh3l)

print "---- Coordinates of Hydrogen atoms in left and right versions of the molecule ----\n"
print "nh3l:\n", nh3Hsel.subset(nh3l).get_positions(), "\n"
print "nh3r:\n", nh3Hsel.subset(nh3r).get_positions(), "\n"
"""
3 - SELECTION VALIDATION

As a safety against mistakes, by default, any AtomSelection has its "validate" property initialised to True.
This means that whenever the selection is used to create a subset or make a transform a check is performed to verify
that the chemical symbols of the Atoms object it is operating on is the same as the one on which it was originally
created. In other words, selections shouldn't be able to operate on structures they don't refer to.
"""

# Create two structures
a1 = Atoms('HCO')
a2 = Atoms('FeAgAu')

# Create a selection
sel1 = AtomSelection.from_sphere(a1, [0, 0, 0], 0.1)

# Try using it on the wrong structure
try:
    a0 = sel1.subset(a2)
except ValueError as e:
    print "An error has verified: \n>\t", e