File: rough_test.py

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (107 lines) | stat: -rw-r--r-- 3,562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
## Automatically adapted for numpy.oldnumeric Jun 27, 2008 by -c

# $Id$
#
#  Copyright (C) 2004  Rational Discovery LLC
#         All Rights Reserved
#

Replaced numpy.oldnumeric with numpy methods - Jan 2015, PGedeck
"""
#pylint: disable=E1101,C0111,R0904
import unittest
import numpy as np
from rdkit import DistanceGeometry as DG


def feq(v1, v2, tol2=1e-4):
  return abs(v1 - v2) <= tol2


class TestCase(unittest.TestCase):

  def setUp(self):
    pass

  def test1SmoothPass(self):
    arr = np.array([[0, 1.0, 5.0], [1.0, 0, 1.0], [0.0, 1.0, 0]], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    self.assertTrue(feq(arr[0, 2], 2.0))
    self.assertTrue(feq(arr[2, 0], 0.0))
    self.assertTrue(feq(arr[0, 1], 1.0))
    self.assertTrue(feq(arr[1, 0], 1.0))
    self.assertTrue(feq(arr[1, 2], 1.0))

  def test2SmoothFail(self):
    arr = np.array([[0, 1.0, 5.0], [1.0, 0, 1.0], [3.0, 1.0, 0]], np.float)
    self.assertFalse(DG.DoTriangleSmoothing(arr))

  def test3SmoothPass(self):
    arr = np.array([[0, 1.1, 5.0], [0.9, 0, 1.1], [0.0, 0.9, 0]], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    self.assertTrue(feq(arr[0, 2], 2.2))
    self.assertTrue(feq(arr[2, 0], 0.0))
    self.assertTrue(feq(arr[0, 1], 1.1))
    self.assertTrue(feq(arr[1, 0], 0.9))
    self.assertTrue(feq(arr[1, 2], 1.1))

  def test4Embed(self):
    arr = np.array([[0, 1.0, 5.0], [1.0, 0, 1.0], [0.0, 1.0, 0]], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    coords = DG.EmbedBoundsMatrix(arr, randomSeed=100)
    v1 = coords[0] - coords[1]
    v2 = coords[1] - coords[2]
    d1 = np.dot(v1, v1)
    self.assertTrue(feq(d1, 1.0, 0.001))
    d2 = np.dot(v2, v2)
    self.assertTrue(feq(d2, 1.0, 0.001))

  def test5EmbedFail(self):
    arr = np.array([[0, 1.0, 5.0], [1.0, 0, 1.0], [3.0, 1.0, 0]], np.float)
    self.assertRaises(ValueError, lambda: DG.EmbedBoundsMatrix(arr))
    #DG.EmbedBoundsMatrix(arr,randomizeOnFailure=0,randomSeed=1)
    DG.EmbedBoundsMatrix(arr, randomizeOnFailure=1)

  def test6EmbedConstraints(self):
    arr = np.array([[0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [0.99, 1.0, 0.0]], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    coords = DG.EmbedBoundsMatrix(arr, randomSeed=100)
    v1 = coords[0] - coords[1]
    v2 = coords[1] - coords[2]
    d1 = np.dot(v1, v1)

    self.assertTrue(feq(d1, 1.0, 2e-3))
    d2 = np.dot(v2, v2)
    self.assertTrue(feq(d2, 1.0, 2e-3))
    arr = np.array([[0.0, 1.0, 1.0, 1.01], [1.0, 0.0, 1.0, 1.0], [1.0, 1.0, 0.0, 1.0],
                    [0.99, 1.0, 1.0, 0.0]], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    coords = DG.EmbedBoundsMatrix(arr)
    v1 = coords[0] - coords[1]
    v2 = coords[1] - coords[2]
    d1 = np.dot(v1, v1)
    self.assertTrue(feq(d1, 1.0, 1e-3))
    d2 = np.dot(v2, v2)
    self.assertTrue(feq(d2, 1.0, 1e-3))

    return
    # this test is currently (rev:4769) passing on windows and
    # failing on linux.  It's kind of dependent on fp precision, so
    # it's probably ok to ditch it.
    arr = np.array([[0.0, 1.0, 1.0, 1.0],
                    [1.0, 0.0, 1.0, 1.0],
                    [1.0, 1.0, 0.0, 1.0],
                    [1.0, 1.0, 1.0, 0.0], ], np.float)
    self.assertTrue(DG.DoTriangleSmoothing(arr))
    coords = DG.EmbedBoundsMatrix(arr, randomSeed=100)
    v1 = coords[0] - coords[1]
    v2 = coords[1] - coords[2]
    d1 = np.dot(v1, v1)
    self.assertTrue(feq(d1, 1.0, 1e-3))
    d2 = np.dot(v2, v2)
    self.assertTrue(feq(d2, 1.0, 1e-3))


if __name__ == '__main__':
  unittest.main()