-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
337 lines (298 loc) · 14.7 KB
/
conftest.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import unittest
import MolecularCoordinates
import conftest
class ConfTestCase(unittest.TestCase):
def testSimpleHetConf(self):
""" A simple test (using the same molecule) of the heterogeneous case
A pyramidal form for CH3
"""
(q, n) = conftest.SimpleHetConf()
self.assertEqual(q, True)
self.assertEqual(len(n), 6)
def testSimpleHomConf(self):
""" A simple test (using the same molecule) of the homogenous case
A cube of hydrogens
"""
(q, n) = conftest.SimpleHomConf()
self.assertEqual(q, True)
self.assertEqual(len(n), 48) #I believe the answer is 48, though I am not positive off the top of my head, and it could be higher
def testMirrorImageConf(self):
""" A test of mirror images
Mirror image conformations of gauche n-butane (each independently optimized using PM3 in Gaussian03 using default convergence criteria)
"""
(q, n) = conftest.MirrorImageConf()
self.assertEqual(q, True)
self.assertEqual(len(n), 2) #I believe the correct answer is 2
def testBuckminsterfullerene(self):
""" A test of Buckminsterfullerene with itself
"""
(q, n) = conftest.Buckminsterfullerene()
self.assertEqual(q, True)
self.assertEqual(len(n), 120) #A result of 120 seems reasonable (symmetry number is 60)
def testDistinctJP10Conf(self):
""" A test of distinct JP-10 conformations
The conformations differ in the puckering of one of the rings; conformations come from CBS-QB3 calculations with opt=verytight and int=ultrafine (JP10_A.log and JP10_B.log in my records)
"""
(q, n) = conftest.DistinctJP10Conf()
self.assertEqual(q, False)
def testAtomTypeSwapConf(self):
""" A test of molecules with swapped atom types
The two "conformations" have atoms in the same position, but the types of atoms in each position are different, and thus should produce a value of False when compared
"""
(q, n) = conftest.AtomTypeSwapConf()
self.assertEqual(q, False)
def testLongLinearChainHomConf(self):
""" A test of a long linear homogeneous chain
There should only be one unique atom mapping here by the construction of the distances (each atom-to-atom distance should be unique ; the function LongLinearChainConf is actually more useful for timing of scaling for large numbers of atoms, but it doesn't hurt to also check that the results are what we expect
"""
(q, n) = conftest.LongLinearChainHomConf(30)#use a chain of length 30 for this test
self.assertEqual(q, True)
self.assertEqual(len(n), 1)
def testLongLinearChainHetConf(self):
""" A test of a long linear heterogeneous chain
There should only be one unique atom mapping here due to the use of different atom types
"""
(q, n) = conftest.LongLinearChainHomConf(30)#use a chain of length 30 for this test
self.assertEqual(q, True)
self.assertEqual(len(n), 1)
# def testOptConf(self):
# """ A test of equivalent conformations of a large molecule obtained from optimization with different potential energy calculation methods
#
# """
# #a = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
# #b = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
# #alternatively, we could play around with Atol/Rtol to see how tight they need to be
# (q, n) = MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.05)
# print q
#
# def testInitialConditionConf(self):
# """ A test of equivalent conformations of a large molecule optimized with different initial conditions
#
# The same potential energy calculation method is used in both cases. Default convergence criterion of Gaussian03 are used.
# """
# #a = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
# #b = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
# #it may be appropriate to use Rtol here, particularly for a large molecule
# (q, n) = MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.05)
# self.assertEqual(q, True)
def testCalcDistDev(self):
""" A test of distance deviations, given a mapping
Uses mirror image conformations of gauche n-butane (each independently optimized using PM3 in Gaussian03 using default convergence criteria)
"""
ac = [[-1.5846, -0.5216, 0.1338],
[-1.1512, -1.5146, -0.0477 ],
[-1.7781, -0.4440, 1.2120 ],
[-2.5555, -0.4907, -0.3770 ],
[-0.6751, 0.5855, -0.3509 ],
[-1.1705, 1.5633, -0.1896 ],
[-0.5293, 0.5028, -1.4463 ],
[ 0.6751, 0.5854, 0.3509 ],
[ 1.1705, 1.5633, 0.1895 ],
[ 0.5294, 0.5028, 1.4463 ],
[ 1.5846, -0.5216, -0.1338 ],
[ 2.5554, -0.4908, 0.3772 ],
[ 1.1510, -1.5146, 0.0475 ],
[ 1.7783, -0.4438, -1.2120]]
aa = [6, 1, 1, 1, 6, 1, 1, 6, 1, 1, 6, 1, 1, 1]
bc = [[ -1.5845, -0.5216, -0.1338],
[-1.7784, -0.4438, -1.2120 ],
[-1.1509, -1.5146, 0.0474 ],
[-2.5553, -0.4910, 0.3773 ],
[-0.6751, 0.5855, 0.3508 ],
[-0.5293, 0.5028, 1.4463 ],
[-1.1705, 1.5634, 0.1895 ],
[ 0.6751, 0.5855, -0.3508 ],
[ 1.1705, 1.5633, -0.1893 ],
[ 0.5294, 0.5030, -1.4463 ],
[ 1.5845, -0.5216, 0.1338 ],
[ 1.1510, -1.5146, -0.0478 ],
[ 2.5555, -0.4908, -0.3770 ],
[ 1.7780, -0.4441, 1.2121 ]]
ba = [6, 1, 1, 1, 6, 1, 1, 6, 1, 1, 6, 1, 1, 1]
a = MolecularCoordinates.MolecularGeometry(aa,ac)
b = MolecularCoordinates.MolecularGeometry(ba,bc)
#atomMap = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14} #a naive mapping
atomMap = {1: 1, 2: 3, 3: 2, 4: 4, 5: 5, 6: 7, 7: 6, 8: 8, 9: 9, 10: 10, 11: 11, 12: 13, 13: 12, 14: 14} #a "correct" mapping (there is also one other "correct" mapping)
(distDevAbs,distDevRel) = MolecularCoordinates.calcDistanceDeviationsGivenMapping(a, b, atomMap)
distDevAbsMax = MolecularCoordinates.dictionaryMaxAbs(distDevAbs)
distDevRelMax = MolecularCoordinates.dictionaryMaxAbs(distDevRel)
self.assertAlmostEqual(distDevAbsMax, 0.000528777418128, 5)
self.assertAlmostEqual(distDevRelMax, 0.000145546853437, 5)
def SimpleHetConf():
a = MolecularCoordinates.MolecularGeometry([6,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1]])
b = MolecularCoordinates.MolecularGeometry([6,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1]])
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.01)
def SimpleHomConf():
a = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
b = MolecularCoordinates.MolecularGeometry([1,1,1,1,1,1,1,1],[[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,1,1],[1,0,1],[1,1,0],[1,1,1]])
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.01)
def MirrorImageConf():
ac = [[-1.5846, -0.5216, 0.1338],
[-1.1512, -1.5146, -0.0477 ],
[-1.7781, -0.4440, 1.2120 ],
[-2.5555, -0.4907, -0.3770 ],
[-0.6751, 0.5855, -0.3509 ],
[-1.1705, 1.5633, -0.1896 ],
[-0.5293, 0.5028, -1.4463 ],
[ 0.6751, 0.5854, 0.3509 ],
[ 1.1705, 1.5633, 0.1895 ],
[ 0.5294, 0.5028, 1.4463 ],
[ 1.5846, -0.5216, -0.1338 ],
[ 2.5554, -0.4908, 0.3772 ],
[ 1.1510, -1.5146, 0.0475 ],
[ 1.7783, -0.4438, -1.2120]]
aa = [6, 1, 1, 1, 6, 1, 1, 6, 1, 1, 6, 1, 1, 1]
bc = [[ -1.5845, -0.5216, -0.1338],
[-1.7784, -0.4438, -1.2120 ],
[-1.1509, -1.5146, 0.0474 ],
[-2.5553, -0.4910, 0.3773 ],
[-0.6751, 0.5855, 0.3508 ],
[-0.5293, 0.5028, 1.4463 ],
[-1.1705, 1.5634, 0.1895 ],
[ 0.6751, 0.5855, -0.3508 ],
[ 1.1705, 1.5633, -0.1893 ],
[ 0.5294, 0.5030, -1.4463 ],
[ 1.5845, -0.5216, 0.1338 ],
[ 1.1510, -1.5146, -0.0478 ],
[ 2.5555, -0.4908, -0.3770 ],
[ 1.7780, -0.4441, 1.2121 ]]
ba = [6, 1, 1, 1, 6, 1, 1, 6, 1, 1, 6, 1, 1, 1]
a = MolecularCoordinates.MolecularGeometry(aa,ac)
b = MolecularCoordinates.MolecularGeometry(ba,bc)
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.001)
def Buckminsterfullerene():
a = MolecularCoordinates.readMOLFile('c60_c.mol')
b = MolecularCoordinates.readMOLFile('c60_c.mol')
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.01)
def DistinctJP10Conf():
a = MolecularCoordinates.readMOLFile('JP10A.mol')
b = MolecularCoordinates.readMOLFile('JP10B.mol')
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.10)
def AtomTypeSwapConf():
a = MolecularCoordinates.MolecularGeometry([8,1,1],[[0,0,0],[1,0,0],[0,1,0]])
b = MolecularCoordinates.MolecularGeometry([1,8,1],[[0,0,0],[1,0,0],[0,1,0]])
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.01)
def LongLinearChainHomConf(n):
#n represents the number of atoms in the chain
#all the atom-to-atom distances should be unique by the "binary" construction of the coordinates
atomtypes = [1 for i in range(0,n)]
atomcoor = [[2**i,0,0] for i in range(0,n)]
a = MolecularCoordinates.MolecularGeometry(atomtypes,atomcoor)
b = MolecularCoordinates.MolecularGeometry(atomtypes,atomcoor)
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.5)
def LongLinearChainHetConf(n):
#n represents the number of atoms in the chain
atomtypes = [i for i in range(0,n)]
atomcoor = [[i,0,0] for i in range(0,n)]
a = MolecularCoordinates.MolecularGeometry(atomtypes,atomcoor)
b = MolecularCoordinates.MolecularGeometry(atomtypes,atomcoor)
return MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=0.5)
def LongLinearChainHetConfDist(n):
#n represents the number of atoms in the chain
atomtypes = [i for i in range(0,n)]
atomcoor = [[i,0,0] for i in range(0,n)]
a = MolecularCoordinates.MolecularGeometry(atomtypes,atomcoor)
return a.getDistanceMappings()
if __name__ == '__main__':
from timeit import Timer
# import math
# import conftest
# conftest.JP10CalcDistDev()
startup = """import MolecularCoordinates
import conftest
"""
test1 = "(q, n) = conftest.SimpleHetConf()"
test2 = "(q, n) = conftest.SimpleHomConf()"
test3 = "(q, n) = conftest.MirrorImageConf()"
test4 = "(q, n) = conftest.Buckminsterfullerene()"
test5 = "(q, n) = conftest.DistinctJP10Conf()"
test6 = "(q, n) = conftest.LongLinearChainHomConf(75)"
test7 = "(q, n) = conftest.LongLinearChainHomConf(150)"
t = Timer(test1,startup)
times = t.repeat(repeat=5,number=1000)
print "test1 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test2, startup)
times = t.repeat(repeat=5,number=10)
print "test2 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test3, startup)
times = t.repeat(repeat=5,number=100)
print "test3 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test4, startup)
times = t.repeat(repeat=1,number=1)
print "test4 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test5, startup)
times = t.repeat(repeat=5,number=100)
print "test5 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test6, startup)
times = t.repeat(repeat=3,number=1)
print "test6 took %.3f seconds (%s)"%(min(times), times)
t = Timer(test7, startup)
times = t.repeat(repeat=3,number=1)
print "test7 took %.3f seconds (%s)"%(min(times), times)
# JP10startup = """import MolecularCoordinates
#import conftest
#a = MolecularCoordinates.readMOLFile('JP10A.mol')
#b = MolecularCoordinates.readMOLFile('JP10B.mol')
# """
#steps = 117
#mi=-9.0
#max=0.36
#steps=96
#min=-7.0
#max=0.68
# for i in range(0, steps+1):
# j=mi+i*(max-mi)/steps
# t = Timer("(q, n) = MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=%s)"%(math.exp(j)), JP10startup)
# times = t.repeat(repeat=10,number=1)
# #print j, times, q, len(n)
# print j, min(times)
#print j, times
#print "test8 took %.3f seconds (%s)"%(min(times), times)
# a = MolecularCoordinates.readMOLFile('JP10A.mol')
# b = MolecularCoordinates.readMOLFile('JP10B.mol')
# (q, n) = MolecularCoordinates.checkConformationalEquivalence(a, b, Atol=1.2)
# print len(n), n
# for i in range(0, steps+1):
# j=min+i*(max-min)/steps
# (q, n) = MolecularCoordinates.checkConformationalEquivalence(b, a, Atol=math.exp(j))
# print j, math.exp(j), q, len(n)
#for i in range(1,301):
# t = Timer("(q, n) = conftest.LongLinearChainHetConf(%s)"%(i), startup)
# times = t.repeat(repeat=1,number=1)
# print (min(times))
#for i in range(1,301):
# t = Timer("(q, n) = conftest.LongLinearChainHomConf(%s)"%(i), startup)
# times = t.repeat(repeat=1,number=1)
# print (min(times))
print "\nContinuing with tests..."
unittest.main(testRunner = unittest.TextTestRunner(verbosity=2))
def JP10CalcDistDev():
""" A test of distance deviations, given a mapping
"""
a = MolecularCoordinates.readMOLFile('JP10A.mol')
b = MolecularCoordinates.readMOLFile('JP10B.mol')
#atomMap = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15, 16:16, 17:17, 18:18, 19:19, 20:20, 21:21, 22:22, 23:23, 24:24, 25:25, 26:26} #"correct" mapping
#atomMap = {1: 2, 2: 1, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17, 18: 18, 19: 19, 20: 20, 21: 21, 22: 22, 23: 24, 24: 25, 25: 26, 26: 23}#test mapping #15
atomMap = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17, 18: 18, 19: 19, 20: 20, 21: 21, 22: 22, 23: 24, 24: 25, 25: 26, 26: 23} #test mapping #13
(distDevAbs,distDevRel) = MolecularCoordinates.calcDistanceDeviationsGivenMapping(a, b, atomMap)
distDevAbsMax = MolecularCoordinates.dictionaryMaxAbs(distDevAbs)
distDevRelMax = MolecularCoordinates.dictionaryMaxAbs(distDevRel)
print distDevAbsMax
def MM4ReadMOLWrite():
""" A test of MM4 reading and MOL, XYZ writing
"""
mg1=MolecularCoordinates.readMM4File('JP10stochFixedStruct.out',1)
mg2=MolecularCoordinates.readMM4File('JP10stochFixedStruct.out',295)
mg1a=MolecularCoordinates.readMM4File('JP10stochFixedStruct.out',253)
mg1.writeMOLFile('JP10_MM4_1.mol', 'JP10_MM4_1')
mg2.writeMOLFile('JP10_MM4_8.mol', 'JP10_MM4_8')
mg1a.writeMOLFile('JP10_MM4_7.mol', 'JP10_MM4_7')
mg1.perceiveConnectivity()
mg1.writeMOLFile('JP10_MM4_1_conn.mol', 'JP10_MM4_1', connectivity=True)
mg1.writeXYZFile('JP10_MM4_1.xyz', 'JP10_MM4_1')
print MolecularCoordinates.checkConformationalEquivalence(mg1, mg1a, Atol=0.02)
atomMap = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15, 16:16, 17:17, 18:18, 19:19, 20:20, 21:21, 22:22, 23:23, 24:24, 25:25, 26:26} #"correct" mapping
(distDevAbs,distDevRel) = MolecularCoordinates.calcDistanceDeviationsGivenMapping(mg1, mg1a, atomMap)
distDevAbsMax = MolecularCoordinates.dictionaryMaxAbs(distDevAbs)
distDevRelMax = MolecularCoordinates.dictionaryMaxAbs(distDevRel)
print distDevAbsMax