Ejemplo n.º 1
0
    def setUp(self):
        self.paramTxt = """
BeginParams
  family=Acceptor radius=0.5 profile=Box
EndParams
"""
        self.p = FeatMapParser.FeatMapParser()
Ejemplo n.º 2
0
  def test_FeatMapParser(self):
    # We can use a string
    p = FeatMapParser.FeatMapParser(data=self.data)
    fm = p.Parse()
    self.assertEqual(fm.GetNumFeatures(), 3)
    self.assertEqual([x.GetFamily() for x in fm.GetFeatures()],
                     ['Acceptor', 'Aromatic', 'Acceptor'])

    # We can use a list of strings
    p = FeatMapParser.FeatMapParser(data=self.data.split('\n'))
    fm = p.Parse()
    self.assertEqual(fm.GetNumFeatures(), 3)
    self.assertEqual([x.GetFamily() for x in fm.GetFeatures()],
                     ['Acceptor', 'Aromatic', 'Acceptor'])

    # and a stream
    with closing(StringIO(self.data)) as file:
      p = FeatMapParser.FeatMapParser(file=file)
    fm = p.Parse()
    self.assertEqual(fm.GetNumFeatures(), 3)
    self.assertEqual([x.GetFamily() for x in fm.GetFeatures()],
                     ['Acceptor', 'Aromatic', 'Acceptor'])
Ejemplo n.º 3
0
  def test_ParseErrors(self):
    # Typos in scoreMode or dirscoreMode section
    data = "scoreMode = typo\nbeginParams\nfamily=Acceptor radius=1.5\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    data = "dirscoremode = typo\nbeginParams\nfamily=Acceptor radius=1.5\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    data = "typo = All\nbeginParams\nfamily=Acceptor radius=1.5\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    # Typos in paramBlock
    data = "beginTypo\nfamily=Acceptor radius=1.5\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    data = "beginParams\nfamily=Acceptor radius=1.5\nEndTypo"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    data = "beginParams\ntypo=Acceptor radius=1.5\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    data = "beginParams\nprofile=Typo\nEndParams"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)

    # Typos in points block
    data = "BeginPoints\npos=(1.0, 0.0, 5.0, 4.0)\nEndPoints"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(ValueError, p.Parse)

    data = "BeginPoints\npos=(1.0, 0.0, 5.0) typo=Acceptor\nEndPoints"
    p = FeatMapParser.FeatMapParser(data=data)
    self.assertRaises(FeatMapParser.FeatMapParseError, p.Parse)
Ejemplo n.º 4
0
  def test1Basics(self):
    p = FeatMapParser.FeatMapParser()
    p.SetData(self.data)
    fm = p.Parse()
    self.assertTrue(fm.scoreMode == FeatMaps.FeatMapScoreMode.Best)
    self.assertTrue(fm.dirScoreMode == FeatMaps.FeatDirScoreMode.DotFullRange)
    self.assertTrue(fm.GetNumFeatures() == 3)

    feats = fm.GetFeatures()
    self.assertTrue(feq(feats[0].weight, 1.25))
    self.assertTrue(feq(feats[1].weight, 2.0))
    self.assertTrue(feq(feats[2].weight, 1.25))

    self.assertTrue(len(feats[0].featDirs) == 1)
    self.assertTrue(len(feats[1].featDirs) == 2)
    self.assertTrue(len(feats[2].featDirs) == 0)

    fams = [x.GetFamily() for x in feats]
    self.assertTrue(fams == ['Acceptor', 'Aromatic', 'Acceptor'])
Ejemplo n.º 5
0
    def test1Basics(self):
        txt = """

ScoreMode=Best
DirScoreMode=DotFullRange

BeginParams
  family=Aromatic radius=2.5 width=1.0 profile=Triangle
  family=Acceptor radius=1.5
EndParams

# optional
BeginPoints
  family=Acceptor pos=(1.0, 0.0, 5.0) weight=1.25 dir=(1, 1, 0)
  family=Aromatic pos=(0.0,1.0,0.0) weight=2.0 dir=(0,0,1) dir=(0,0,-1)
  family=Acceptor pos=(1.0,1.0,2.0) weight=1.25
EndPoints

"""
        p = FeatMapParser.FeatMapParser()
        p.SetData(txt)
        fm = p.Parse()
        self.assertTrue(fm.scoreMode == FeatMaps.FeatMapScoreMode.Best)
        self.assertTrue(
            fm.dirScoreMode == FeatMaps.FeatDirScoreMode.DotFullRange)
        self.assertTrue(fm.GetNumFeatures() == 3)

        feats = fm.GetFeatures()
        self.assertTrue(feq(feats[0].weight, 1.25))
        self.assertTrue(feq(feats[1].weight, 2.0))
        self.assertTrue(feq(feats[2].weight, 1.25))

        self.assertTrue(len(feats[0].featDirs) == 1)
        self.assertTrue(len(feats[1].featDirs) == 2)
        self.assertTrue(len(feats[2].featDirs) == 0)

        fams = [x.GetFamily() for x in feats]
        self.assertTrue(fams == ['Acceptor', 'Aromatic', 'Acceptor'])