示例#1
0
 def test_custom1_2(self):
     p = PartiallyConstructed(partiallyConstructedTest.Custom1,
                              'a',
                              g='something')
     p.with_attributes(attr1=4, attr2=5, attr3=6)
     full = p('b', 'c', 'd', 'e', 'f')
     self.assertEqual(full.string1, 'a, b, c, d, e, f, g')
     self.assertEqual(full.attr_string(), '4, 5, 6')
示例#2
0
 def test_custom1_1(self):
     p = PartiallyConstructed(partiallyConstructedTest.Custom1,
                              4,
                              5,
                              some_kwarg='something')
     full = p(6)
     self.assertEqual(full.string1, '4, 5, 6, hello, world, some_kwarg')
示例#3
0
 def test_custom1_3(self):
     # Should be okay as long as keyword versions are used in both cases...
     p = PartiallyConstructed(
         partiallyConstructedTest.Custom1,
         arg1='a1',
         arg3='a3',
         another_kwarg='kwarg',
         arg5='a5',
     )
     full = p(arg2='a2', arg4='a4')
     self.assertEqual(full.string1, 'a1, a2, a3, a4, a5, another_kwarg')
示例#4
0
def MolecularPropertyDerivative(prop, representation=CartesianRepresentation, order=1):
    """ Factory for creating `MolecularProperty` subclasses that represent the nth derivative
     of a `MolecularProperty` with respect to some set of coordinates.

     Several possibilities for `representation`:  If it's a `Representation` subclass, then we want that representation
     of the molecule in question (used when requesting the derivative).  If it's a representation instance, then we
     want the Derivative with respect to that specific representation (raises an error if it is not compatible).
     If it's an arbitrary callable, then the callable is called with the contents of the file and should return
     a representation, which the (typically parsed-from-a-file) derivative is considered to be with respect to.
     The default is `CartesianRepresentation`.

     Derivative properties can be automatically or manually transformed to other representations.
    """
    if not issubclass(prop, MolecularProperty):
        raise TypeError
    if raises_error(int, order):
        raise TypeError
    name = '_{1}Derivative{0}'.format(order, prop.__name__)
    if name in DerivativeProperty.known_subclasses:
        ret_val = PartiallyConstructed(DerivativeProperty.known_subclasses[name])
    else:
        ret = type(name, (DerivativeProperty,), {})
        DerivativeProperty.known_subclasses[name] = ret
        ret_val = PartiallyConstructed(ret)
    ret_val.with_attributes(order=order, representation=representation)
    return ret_val
示例#5
0
 def test_custom_double(self):
     p = PartiallyConstructed(partiallyConstructedTest.Custom1, "a", g="something")
     p.with_attributes(attr1="a1")
     p.with_args("b")
     q = PartiallyConstructed(p, arg5="e", h="blah")
     q.with_attributes(attr3="a3")
     q.with_kwargs(arg4="d", f="kwarg")
     q.with_args("c")
     full = q(i="something else")
     full.attr2 = "a2"
     self.assertEqual(full.string1, "a, b, c, d, e, f, g, h, i")
     self.assertEqual(full.attr_string(), "a1, a2, a3")
示例#6
0
 def test_custom1_2(self):
     p = PartiallyConstructed(partiallyConstructedTest.Custom1, "a", g="something")
     p.with_attributes(attr1=4, attr2=5, attr3=6)
     full = p("b", "c", "d", "e", "f")
     self.assertEqual(full.string1, "a, b, c, d, e, f, g")
     self.assertEqual(full.attr_string(), "4, 5, 6")
示例#7
0
 def test_custom_double(self):
     p = PartiallyConstructed(partiallyConstructedTest.Custom1,
                              'a',
                              g='something')
     p.with_attributes(attr1='a1')
     p.with_args('b')
     q = PartiallyConstructed(p, arg5='e', h='blah')
     q.with_attributes(attr3='a3')
     q.with_kwargs(arg4='d', f="kwarg")
     q.with_args('c')
     full = q(i='something else')
     full.attr2 = 'a2'
     self.assertEqual(full.string1, 'a, b, c, d, e, f, g, h, i')
     self.assertEqual(full.attr_string(), 'a1, a2, a3')
示例#8
0
 def in_units(cls, units):
     return PartiallyConstructed(cls, units=units)