def test_fromCartesian(self): """MageList fromCartesian() should return new list with ACG coordinates """ point = MagePoint([.1,.2,.3]) m = MageList([point]*5,Color='green') res = m.toCartesian().fromCartesian() self.assertEqual(str(m),str(res))
def test_fromCartesian(self): """MageList fromCartesian() should return new list with ACG coordinates """ point = MagePoint([.1, .2, .3]) m = MageList([point] * 5, Color='green') res = m.toCartesian().fromCartesian() self.assertEqual(str(m), str(res))
def test_toCartesian(self): """MageList toCartesian should return new list""" m = MageList([self.null],Color='green') res = m.toCartesian() self.assertEqual(len(m), len(res)) self.assertEqual(m.Color,res.Color) self.assertEqual(res[0].Coordinates,[1,1,1]) m.Color='red' self.assertEqual(res.Color,'green') m = MageList([self.properties]) self.assertRaises(ValueError,m.toCartesian)
def test_toArray_coords_only(self): """MageList toArray should return the correct array""" m = MageList(self.empty_list) self.assertEqual(m.toArray(include_radius=False), array(())) m = MageList(self.first_list, Radius=0.3) self.assertEqual(m.toArray(include_radius=False), array([[0, 0, 0], [2.0, 4.0, 6.0]])) m = MageList(self.radii) self.assertEqual(m.toArray(include_radius=False), array([[2, 2, 2], [3, 3, 3]])) m = MageList(self.radii, Radius=0.4) self.assertEqual(m.toArray(include_radius=False), array([[2, 2, 2], [3, 3, 3]])) m = MageList(self.single_list) # radius = None self.assertEqual(m.toArray(include_radius=False), array([[1, 1, 1]]))
def test_init(self): """MageList should init correctly with data""" m = MageList(self.minimal_list) self.assertEqual(str(m), "@dotlist\n" + str(self.null)) m = MageList(self.multi_list, 'x', Off=True, Color='green', NoButton=True) self.assertEqual(str(m), "@dotlist {x} off nobutton color=green\n" + \ '\n'.join(10 * [str(self.properties)])) m = MageList(self.first_list,NoButton=True,Color='red', \ Style='vector', Radius=0.03, Width=3, Label='test') self.assertEqual(str(m), "@vectorlist {test} nobutton color=red " + \ "radius=0.03 width=3\n" + str(self.null) + '\n' + str(self.properties))
def test_toArray_radii(self): """MageList toArray should return the correct array""" m = MageList(self.empty_list) self.assertEqual(m.toArray(),array(())) m = MageList(self.first_list,Radius=.3) self.assertEqual(m.toArray(),array([[0,0,0,0.3],[2.0,4.0,6.0,0.3]])) m = MageList(self.radii) self.assertEqual(m.toArray(), array([[2,2,2,.1],[3,3,3,.5]])) m = MageList(self.radii,Radius=.4) self.assertEqual(m.toArray(), array([[2,2,2,.1],[3,3,3,.5]])) m = MageList(self.single_list) #radius = None self.assertRaises(ValueError,m.toArray)
def setUp(self): self.point = MagePoint([0, 0, 0], 'x') self.ml = MageList([self.point], Label='y', Color='green') self.mg1 = MageGroup([self.ml], Label='z') self.mg2 = MageGroup([self.ml, self.ml], Label='b') self.kin = Kinemage(1) self.kin.Groups = [self.mg1, self.mg2]
def test_fromCartesian(self): """MageGroup fromCartesian should return a new MageGroup""" point = MagePoint([.1, .2, .3]) l = MageList([point] * 5, Color='red') m = MageGroup([l], Radius=0.02, Subgroup=True) mg = MageGroup([m]) res = mg.toCartesian().fromCartesian() self.assertEqual(str(mg), str(res))
def test_iterPoints(self): """MageList iterPoints should yield all points in self""" m = MageList(self.single_list) for point in m.iterPoints(): assert isinstance(point, MagePoint) self.assertEqual(len(list(m.iterPoints())), 1) m = MageList(self.multi_list) for point in m.iterPoints(): assert isinstance(point, MagePoint) self.assertEqual(len(list(m.iterPoints())), 10)
def test_fromCartesian(self): """Kinemage fromCartesian should return Kinemage with A,C,G(,U) coords """ point = MagePoint([.1, .2, .3]) l = MageList([point] * 5, Color='red') m1 = MageGroup([l], Radius=0.02, Subgroup=True) m2 = MageGroup([l], Radius=0.02) mg = MageGroup([m1]) k = Kinemage(Count=1, Groups=[mg, m2]) res = k.toCartesian().fromCartesian() self.assertEqual(str(k), str(res))
def setUp(self): """Define some standard lists and groups.""" self.p1 = MagePoint([0, 1, 0], Color='green', Label='x') self.p0 = MagePoint([0, 0, 0]) self.min_list = MageList([self.p0] * 2, 'y') self.max_list = MageList([self.p1]*5,'z',Color='blue',Off=True, \ Style='ball') self.min_group = MageGroup([self.min_list], Label="min_group") self.max_group = MageGroup([self.min_list, self.max_list], Color='red', Label="max_group", Style='dot') self.nested = MageGroup([self.min_group, self.max_group], Label='nest', Color='orange', Radius=0.3, Style='vector') self.empty = MageGroup(Label='empty', Color='orange', NoButton=True, Style='vector', RecessiveOn=False)
def MageListFromString(line): """Returns a new MageList, created from a string representation""" result = MageList() trans = {'off':('Off',True),\ 'on':('Off',False),\ 'color':'Color',\ 'radius':'Radius',\ 'nobutton':('NoButton',True),\ 'angle':'Angle',\ 'width':'Width',\ 'face':'Face',\ 'font':'Font',\ 'size':'Size'} line = re.sub('=\s*','=',line) label = extract_delimited(line, '{', '}') if label is not None: pieces = line.replace('{'+label+'}', '').split() else: pieces = line.split() style = pieces[0].strip('@')[:-4] #take off the 'list' part if style in MageList.KnownStyles: result.Style = style else: raise ValueError,"Unknown style: %s"%(style) result.Label = label #process all optional pieces for piece in pieces[1:]: try: key,value = [item.strip() for item in piece.split('=')] key = trans[key] except ValueError: #unpack list of wrong size key,value = trans[piece][0],trans[piece][1] #KeyError will be raised in case of an unkown key setattr(result,key,value) return result
def test_iterPoints(self): """MageList iterPoints should yield all points in self""" m = MageList(self.single_list) for point in m.iterPoints(): assert isinstance(point,MagePoint) self.assertEqual(len(list(m.iterPoints())),1) m = MageList(self.multi_list) for point in m.iterPoints(): assert isinstance(point,MagePoint) self.assertEqual(len(list(m.iterPoints())),10)
def test_toCartesian(self): """MageList toCartesian should return new list""" m = MageList([self.null], Color='green') res = m.toCartesian() self.assertEqual(len(m), len(res)) self.assertEqual(m.Color, res.Color) self.assertEqual(res[0].Coordinates, [1, 1, 1]) m.Color = 'red' self.assertEqual(res.Color, 'green') m = MageList([self.properties]) self.assertRaises(ValueError, m.toCartesian)
def test_toArray_coords_only(self): """MageList toArray should return the correct array""" m = MageList(self.empty_list) self.assertEqual(m.toArray(include_radius=False), array(())) m = MageList(self.first_list, Radius=.3) self.assertEqual(m.toArray(include_radius=False), array([[0, 0, 0], [2.0, 4.0, 6.0]])) m = MageList(self.radii) self.assertEqual(m.toArray(include_radius=False), array([[2, 2, 2], [3, 3, 3]])) m = MageList(self.radii, Radius=.4) self.assertEqual(m.toArray(include_radius=False), array([[2, 2, 2], [3, 3, 3]])) m = MageList(self.single_list) #radius = None self.assertEqual(m.toArray(include_radius=False), array([[1, 1, 1]]))
def test_init_empty(self): """MageList should init correctly with no data""" m = MageList() self.assertEqual(str(m), "@dotlist") m = MageList(self.empty_list) self.assertEqual(str(m), "@dotlist")
def test_toArray_radii(self): """MageList toArray should return the correct array""" m = MageList(self.empty_list) self.assertEqual(m.toArray(), array(())) m = MageList(self.first_list, Radius=.3) self.assertEqual(m.toArray(), array([[0, 0, 0, 0.3], [2.0, 4.0, 6.0, 0.3]])) m = MageList(self.radii) self.assertEqual(m.toArray(), array([[2, 2, 2, .1], [3, 3, 3, .5]])) m = MageList(self.radii, Radius=.4) self.assertEqual(m.toArray(), array([[2, 2, 2, .1], [3, 3, 3, .5]])) m = MageList(self.single_list) #radius = None self.assertRaises(ValueError, m.toArray)