/
crystals.py
613 lines (502 loc) · 31.2 KB
/
crystals.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
import os
from checks import checks
import datetime
import time
class crystals(object):
# this class is for crystal parameters for a loaded or created crystal.
# Default absCoefCalc is set to 'Average'
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="",modelFile=""):
self.crystName = crystName
self.type = crystType
self.crystDimX = crystDimX
self.crystDimY = crystDimY
self.crystDimZ = crystDimZ
self.pixelsPerMicron = crystPixPerMic
self.angleP = angleP
self.angleL = angleL
self.absCoefCalc = absCoefCalc
self.modelFile = modelFile
# find the crystal container information, if it was provided when the crystal object was created
self.containerInfoDict = containerInfoDict
if self.checkContainerInfoPresent() == True:
self.getContainerInfo()
self.__creationTime = self.getCreationTime()
def getTimeStampedName(self):
# create a string containing name then timestamp for unique crystal identification
timeStampedName = self.__creationTime + " "*10 + self.crystName
return timeStampedName
def getCreationTime(self):
# get time of creation of current crystal object
ts = time.time()
creationTime = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
return creationTime
def __eq__(self, other) :
"""This method checks to see if a crystal has the same properties as
another crystal
"""
compareProps_self = {attr: getattr(self, attr) for attr in vars(self) if attr not in ('crystName','_crystals__creationTime')}
compareProps_other = {attr: getattr(other, attr) for attr in vars(other) if attr not in ('crystName','_crystals__creationTime')}
return compareProps_self == compareProps_other
def setDimsByCrystType(self):
# depending of the crystal type specified, update the dimensions
# of the crystal to the fixed format below
crystalType = str(self.type).lower()
if crystalType != 'polyhedron':
self.modelFile = ""
self.wireFrameType = ""
else:
self.wireFrameType = 'OBJ'
if crystalType == 'spherical':
self.crystDimY = ""
self.crystDimZ = ""
elif crystalType == 'cylindrical':
self.crystDimZ = ""
elif crystalType == 'polyhedron':
self.crystDimX = ""
self.crystDimY = ""
self.crystDimZ = ""
def checkContainerInfoPresent(self):
# check whether container info has been provided for crystal
try:
self.containerInfoDict["Type"]
except KeyError:
return False
if self.containerInfoDict["Type"] in ('Mixture','Elemental'):
return True
else:
return False
def getContainerInfo(self):
# get info regarding crystal container
self.containerMaterialType = self.containerInfoDict["Type"]
self.containerThickness = self.containerInfoDict["Thickness"]
self.containerDensity = self.containerInfoDict["Density"]
if self.containerMaterialType == 'Mixture':
self.materialMixture = self.containerInfoDict["Mixture"]
elif self.containerMaterialType == 'Elemental':
self.materialElements = self.containerInfoDict["Elements"]
def checkValidInputs(self):
ErrorMessage = ""
# check valid crystal type
crystalType = str(self.type).lower()
if crystalType not in ('cuboid','spherical','cylindrical','polyhedron'):
ErrorMessage += 'Crystal type {} not of compatible format.\n'.format(str(self.type))
# check that relevant crystal dimensions (dependent of crystal type) can be converted to
# non-negative float format (from string format)
if crystalType in ('cuboid','spherical','cylindrical'):
ErrorMessage += checks(self.crystDimX,'x dimension',False).checkIfNonNegFloat()
if crystalType in ('cuboid','cylindrical'):
ErrorMessage += checks(self.crystDimY,'y dimension',False).checkIfNonNegFloat()
if crystalType in ('cuboid'):
ErrorMessage += checks(self.crystDimZ,'z dimension',False).checkIfNonNegFloat()
if crystalType in ('polyhedron'):
ErrorMessage += checks(self.modelFile,'model file',False).checkIfNonBlankString()
if str(self.wireFrameType).lower() != 'obj':
ErrorMessage += 'Wire frame type not of compatible .obj format\n'
# check that crystal pixelsPerMicron can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.pixelsPerMicron,'pixels per micron',False).checkIfNonNegFloat()
# check that crystal angle P and angle L can be converted to float format (from string format)
ErrorMessage += checks(self.angleP,'angle P',True).checkIfFloat()
ErrorMessage += checks(self.angleL,'angle L',True).checkIfFloat()
# check that absCoefCalc value of valid form
if str(self.absCoefCalc).lower() not in ('average','exp','rd3d','rdv2','sequence','saxs','saxsseq'):
ErrorMessage += 'Crystal absorption coefficient {} not of compatible format.\n'.format(str(self.absCoefCalc))
# check container information is valid (if present)
try:
self.containerMaterialType
# check that container type of suitable format
if str(self.containerMaterialType).lower() not in ('mixture','elemental','none'):
ErrorMessage += 'Crystal container type {} not of compatible format.\n'.format(str(self.containerMaterialType))
# check that container thickness can be converted to float and is non-negative
ErrorMessage += checks(self.containerThickness,'container thickness',False).checkIfNonNegFloat()
# check that container density can be converted to float and is non-negative
ErrorMessage += checks(self.containerDensity,'container density',False).checkIfNonNegFloat()
# check that if 'mixture' type specified, then corresponding mixture is a non-empty string
if str(self.containerMaterialType).lower() == 'mixture':
if not isinstance(self.materialMixture, basestring):
ErrorMessage += 'Crystal container mixture not of compatible string format.\n'
elif len(self.materialMixture) == 0:
ErrorMessage += 'Crystal container mixture field is blank.\n'
# check that if 'elemental' type specified, then corresponding element composition is a non-empty string
if str(self.containerMaterialType).lower() == 'elemental':
if not isinstance(self.materialElements, basestring):
ErrorMessage += 'Crystal container elemental composition not of compatible string format.\n'
elif len(self.materialElements) == 0:
ErrorMessage += 'Crystal container elemental composition field is blank.\n'
else:
# check that suitable heavy atom string formatting
ErrorMessage += checks(self.materialElements,'material elemental composition',False).checkHeavyAtomFormat()
except AttributeError:
pass
return ErrorMessage
def extractCrystalInfo(self):
# create a string containing basic information of current crystal
summaryString = "Crystal Name: {}\n".format(str(self.crystName))
summaryString += "Type: {}\n".format(str(self.type))
if str(self.type).lower() in ('cuboid'):
summaryString += "Dimensions: {} {} {} (microns in x,y,z)\n".format(str(self.crystDimX),str(self.crystDimY),str(self.crystDimZ))
elif str(self.type).lower() in ('spherical'):
summaryString += "Diameter: {} microns\n".format(str(self.crystDimX))
elif str(self.type).lower() in ('cylindrical'):
summaryString += "Diameter: {} (microns), Height: {} (microns)\n".format(str(self.crystDimX),str(self.crystDimY))
elif str(self.type).lower() in ('polyhedron'):
summaryString += "Model file: {}\n".format(str(self.modelFile))
summaryString += "Pixels per Micron: {}\n".format(str(self.pixelsPerMicron))
summaryString += "Angle P: {}\n".format(str(self.angleP))
summaryString += "Angle L: {}\n".format(str(self.angleL))
summaryString += "Absorption Coeffient Calculation: {}\n".format(str(self.absCoefCalc))
# if container information was provided, include in summary
try:
self.containerMaterialType
except AttributeError:
return summaryString
if str(self.containerMaterialType).lower() in ('mixture','elemental'):
containerString = "\nContainer Information:\n"
containerString += "Container Type: {}\n".format(str(self.containerMaterialType))
if str(self.containerMaterialType).lower() == 'mixture':
containerString += "Material Mixture: {}\n".format(str(self.materialMixture))
elif str(self.containerMaterialType).lower() == 'elemental':
containerString += "Material Elements: {}\n".format(str(self.materialElements))
containerString += "Container Thickness: {}\n".format(str(self.containerThickness))
containerString += "Container Density: {}\n".format(str(self.containerDensity))
summaryString += containerString
return summaryString
def writeRD3DCrystalBlock(self):
"""Write a text block of crystal information for RADDOSE-3D
Function to write a text block of the crystal properties for a
RADDOSE-3D input file.
"""
crystLines = [] #Inialise empty list
crystLines.append("Crystal") # Append the string - "Crystal" - to the list
crystPropertyDict = vars(self) #create a dictionary from the crystal object properties and corresponding values
# Add a dictionary entry that puts all relevant crystal dimension values into a string (dependent on crystal type)
if str(self.type).lower() in ('cuboid','spherical','cylindrical'):
crystPropertyDict["Dimensions"] = '{} {} {}'.format(self.crystDimX, self.crystDimY, self.crystDimZ)
# Add a dictionary entry that puts the unit cell dimensions into a string (only if present in crystal object)
try:
crystPropertyDict["Unitcell"] = '{} {} {} {} {} {}'.format(self.unitcell_a, self.unitcell_b, self.unitcell_c,
self.unitcell_alpha, self.unitcell_beta, self.unitcell_gamma)
except AttributeError:
pass
# loop through each entry in the dictionary, create a string of the key
# and value from the dictionary and append that to the list created above
for crystProp in crystPropertyDict:
# create strings for other (non-dimension) crystal inputs
if (crystProp != 'crystDimX' and crystProp != 'crystDimY' and crystProp != 'crystDimZ' and
crystProp != 'crystName' and crystProp != 'containerInfoDict' and crystProp != 'unitcell_a' and
crystProp != 'unitcell_b' and crystProp != 'unitcell_c' and crystProp != 'unitcell_alpha' and
crystProp != 'unitcell_beta' and crystProp != 'unitcell_gamma' and '_crystals__' not in crystProp and
crystPropertyDict[crystProp]):
if crystProp.lower() == "seqfile" or "modelfile":
string = '{} {}'.format(crystProp[0].upper()+crystProp[1:],str(crystPropertyDict[crystProp]).split("/")[-1])
crystLines.append(string)
else:
string = '{} {}'.format(crystProp[0].upper()+crystProp[1:],str(crystPropertyDict[crystProp]))
crystLines.append(string)
# write list entries as a single text block with each list entry joined
# by a new line character
crystBlock = "\n".join(crystLines)
return crystBlock #return the crystal block
class crystals_pdbCode(crystals):
# A subclass for a single pdb file structure
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="",crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="",
modelFile="", pdbcode="", solventHeavyConc=""):
super(crystals_pdbCode, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.pdb = pdbcode
self.solventHeavyConc = solventHeavyConc
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check valid pdb code input
if len(self.pdb) != 4:
ErrorMessage += 'PDB code input {} not of compatible format.\n'.format(str(self.pdb))
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "PDB code: {}\n".format(str(self.pdb))
compositionString += "Solvent Heavy Atom Concentration: {}\n".format(str(self.solventHeavyConc))
return compositionString
class crystals_userDefined(crystals):
# A subclass for a user defined crystal composition
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="", modelFile="",
unitcell_a="", unitcell_b="", unitcell_c="",
unitcell_alpha="", unitcell_beta="", unitcell_gamma="",
numMonomers="", numResidues="", numRNA="", numDNA="",
proteinHeavyAtoms="", solventHeavyConc="", solventFraction=""):
super(crystals_userDefined, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.unitcell_a = unitcell_a
self.unitcell_b = unitcell_b
self.unitcell_c = unitcell_c
self.unitcell_alpha = unitcell_alpha
self.unitcell_beta = unitcell_beta
self.unitcell_gamma = unitcell_gamma
self.numMonomers = numMonomers
self.numResidues = numResidues
self.numRNA = numRNA
self.numDNA = numDNA
self.proteinHeavyAtoms = proteinHeavyAtoms
self.solventHeavyConc = solventHeavyConc
self.solventFraction = solventFraction
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check that unit cell dimensions can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.unitcell_a,'unit cell a dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_b,'unit cell b dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_c,'unit cell c dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_alpha,'unit cell angle alpha',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_beta,'unit cell angle beta',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_gamma,'unit cell angle gamma',True).checkIfNonNegFloat()
# check that number of monomers/residues has been filled in and can be converted to non-negative integers
ErrorMessage += checks(self.numMonomers,'number of monomers',False).checkIfNonNegInt()
ErrorMessage += checks(self.numResidues,'number of residues',False).checkIfNonNegInt()
# check that number of RNA/DNA nucleotides can be converted to non-negative integers
ErrorMessage += checks(self.numRNA,'number of RNA nucleotides',True).checkIfNonNegInt()
ErrorMessage += checks(self.numDNA,'number of DNA nucleotides',True).checkIfNonNegInt()
# check that crystal proteinHeavyAtoms formatting is correct
ErrorMessage += checks(self.proteinHeavyAtoms,'heavy atoms in protein',True).checkHeavyAtomFormat()
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
# check that solvent fraction is float between 0 and 1
ErrorMessage += checks(self.solventFraction,'solvent fraction',True).checkIfFloatBetween01()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "Unit Cell Dimensions: {} {} {} (microns in a,b,c)\n".format(str(self.unitcell_a),str(self.unitcell_b),str(self.unitcell_c))
compositionString += "Unit Cell Angles: {} {} {} (degrees in alpha,beta,gamma)\n".format(str(self.unitcell_alpha),str(self.unitcell_beta),str(self.unitcell_gamma))
compositionString += "Number of Monomers: {}\n".format(str(self.numMonomers))
compositionString += "Number of Residues: {}\n".format(str(self.numResidues))
compositionString += "Number of RNA: {}\n".format(str(self.numRNA))
compositionString += "Number of DNA: {}\n".format(str(self.numDNA))
compositionString += "Protein Heavy Atom number: {}\n".format(str(self.proteinHeavyAtoms))
compositionString += "Solvent Heavy Atom Concentration: {}\n".format(str(self.solventHeavyConc))
compositionString += "Solvent Fraction: {}\n".format(str(self.solventFraction))
return compositionString
class crystals_RADDOSEv2(crystals):
# A subclass for RADDOSE-v2 crystal inputs
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="",angleL="", containerInfoDict={}, absCoefCalc="", modelFile="",
unitcell_a="", unitcell_b="", unitcell_c="",
unitcell_alpha="", unitcell_beta="", unitcell_gamma="",
numMonomers="", numResidues="", numRNA="", numDNA="",
proteinHeavyAtoms="", solventHeavyConc="",solventFraction=""):
super(crystals_RADDOSEv2, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.unitcell_a = unitcell_a
self.unitcell_b = unitcell_b
self.unitcell_c = unitcell_c
self.unitcell_alpha = unitcell_alpha
self.unitcell_beta = unitcell_beta
self.unitcell_gamma = unitcell_gamma
self.numMonomers = numMonomers
self.numResidues = numResidues
self.numRNA = numRNA
self.numDNA = numDNA
self.proteinHeavyAtoms = proteinHeavyAtoms
self.solventHeavyConc = solventHeavyConc
self.solventFraction = solventFraction
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check that unit cell dimensions can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.unitcell_a,'unit cell a dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_b,'unit cell b dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_c,'unit cell c dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_alpha,'unit cell angle alpha',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_beta,'unit cell angle beta',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_gamma,'unit cell angle gamma',True).checkIfNonNegFloat()
# check that number of monomers/residues has been filled in and can be converted to non-negative integers
ErrorMessage += checks(self.numMonomers,'number of monomers',False).checkIfNonNegInt()
ErrorMessage += checks(self.numResidues,'number of residues',False).checkIfNonNegInt()
# check that number of RNA/DNA nucleotides can be converted to non-negative integers
ErrorMessage += checks(self.numRNA,'number of RNA nucleotides',True).checkIfNonNegInt()
ErrorMessage += checks(self.numDNA,'number of DNA nucleotides',True).checkIfNonNegInt()
# check that crystal proteinHeavyAtoms formatting is correct
ErrorMessage += checks(self.proteinHeavyAtoms,'heavy atoms in protein',True).checkHeavyAtomFormat()
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
# check that solvent fraction is float between 0 and 1
ErrorMessage += checks(self.solventFraction,'solvent fraction',True).checkIfFloatBetween01()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "Unit Cell Dimensions: {} {} {} (microns in a,b,c)\n".format(str(self.unitcell_a),str(self.unitcell_b),str(self.unitcell_c))
compositionString += "Unit Cell Angles: {} {} {} (degrees in alpha,beta,gamma)\n".format(str(self.unitcell_alpha),str(self.unitcell_beta),str(self.unitcell_gamma))
compositionString += "Number of Monomers: {}\n".format(str(self.numMonomers))
compositionString += "Number of Residues: {}\n".format(str(self.numResidues))
compositionString += "Number of RNA: {}\n".format(str(self.numRNA))
compositionString += "Number of DNA: {}\n".format(str(self.numDNA))
compositionString += "Protein Heavy Atom number: {}\n".format(str(self.proteinHeavyAtoms))
compositionString += "Solvent Heavy Atom Concentration: {}\n".format(str(self.solventHeavyConc))
compositionString += "Solvent Fraction: {}\n".format(str(self.solventFraction))
return compositionString
class crystals_seqFile(crystals):
# A subclass for sequence file-defined crystal composition
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="", modelFile="",
unitcell_a="", unitcell_b="", unitcell_c="",
unitcell_alpha="", unitcell_beta="", unitcell_gamma="",
numMonomers="", sequenceFile="", proteinHeavyAtoms="",
solventHeavyConc="", solventFraction=""):
super(crystals_seqFile, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.unitcell_a = unitcell_a
self.unitcell_b = unitcell_b
self.unitcell_c = unitcell_c
self.unitcell_alpha = unitcell_alpha
self.unitcell_beta = unitcell_beta
self.unitcell_gamma = unitcell_gamma
self.numMonomers = numMonomers
self.seqFile = sequenceFile
self.proteinHeavyAtoms = proteinHeavyAtoms
self.solventHeavyConc = solventHeavyConc
self.solventFraction = solventFraction
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check that unit cell dimensions can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.unitcell_a,'unit cell a dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_b,'unit cell b dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_c,'unit cell c dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_alpha,'unit cell angle alpha',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_beta,'unit cell angle beta',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_gamma,'unit cell angle gamma',True).checkIfNonNegFloat()
# check that number of monomers has been filled in and can be converted to a non-negative integer
ErrorMessage += checks(self.numMonomers,'number of monomers',False).checkIfNonNegInt()
# check that crystal proteinHeavyAtoms formatting is correct
ErrorMessage += checks(self.proteinHeavyAtoms,'heavy atoms in protein',True).checkHeavyAtomFormat()
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
# check that solvent fraction is float between 0 and 1
ErrorMessage += checks(self.solventFraction,'solvent fraction',True).checkIfFloatBetween01()
# check that sequence file name has been entered
ErrorMessage += checks(self.seqFile,'sequence file',False).checkIfNonBlankString()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "Unit Cell Dimensions: {} {} {} (microns in a,b,c)\n".format(str(self.unitcell_a),str(self.unitcell_b),str(self.unitcell_c))
compositionString += "Unit Cell Angles: {} {} {} (degrees in alpha,beta,gamma)\n".format(str(self.unitcell_alpha),str(self.unitcell_beta),str(self.unitcell_gamma))
compositionString += "Number of Monomers: {}\n".format(str(self.numMonomers))
compositionString += "Protein Heavy Atom number: {}\n".format(str(self.proteinHeavyAtoms))
compositionString += "Solvent Heavy Atom Concentration: {}\n".format(str(self.solventHeavyConc))
compositionString += "Solvent Fraction: {}\n".format(str(self.solventFraction))
compositionString += "Sequence File: {}\n".format(str(self.seqFile))
return compositionString
class crystals_SAXSuserDefined(crystals):
# A subclass for user-defined SAXS crystal composition inputs
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="", modelFile="",
unitcell_a="", unitcell_b="", unitcell_c="",
unitcell_alpha="", unitcell_beta="", unitcell_gamma="",
numResidues="", numRNA="", numDNA="",
proteinHeavyAtoms="", solventHeavyConc="",
solventFraction="", proteinConc=""):
super(crystals_SAXSuserDefined, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.unitcell_a = unitcell_a
self.unitcell_b = unitcell_b
self.unitcell_c = unitcell_c
self.unitcell_alpha = unitcell_alpha
self.unitcell_beta = unitcell_beta
self.unitcell_gamma = unitcell_gamma
self.numResidues = numResidues
self.numRNA = numRNA
self.numDNA = numDNA
self.proteinHeavyAtoms = proteinHeavyAtoms
self.solventHeavyConc = solventHeavyConc
self.solventFraction = solventFraction
self.proteinConc = proteinConc
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check that unit cell dimensions can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.unitcell_a,'unit cell a dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_b,'unit cell b dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_c,'unit cell c dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_alpha,'unit cell angle alpha',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_beta,'unit cell angle beta',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_gamma,'unit cell angle gamma',True).checkIfNonNegFloat()
# check that protein concentration can be converted to non-negative float format (from string)
ErrorMessage += checks(self.proteinConc,'protein concentration',False).checkIfNonNegFloat()
# check that number of residues has been filled in and can be converted to a non-negative integer
ErrorMessage += checks(self.numResidues,'number of residues',False).checkIfNonNegInt()
# check that number of RNA/DNA nucleotides can be converted to non-negative integers
ErrorMessage += checks(self.numRNA,'number of RNA nucleotides',True).checkIfNonNegInt()
ErrorMessage += checks(self.numDNA,'number of DNA nucleotides',True).checkIfNonNegInt()
# check that crystal proteinHeavyAtoms formatting is correct
ErrorMessage += checks(self.proteinHeavyAtoms,'heavy atoms in protein',True).checkHeavyAtomFormat()
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
# check that solvent fraction is float between 0 and 1
ErrorMessage += checks(self.solventFraction,'solvent fraction',True).checkIfFloatBetween01()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "Unit Cell Dimensions: {} {} {} (microns in a,b,c)\n".format(str(self.unitcell_a),str(self.unitcell_b),str(self.unitcell_c))
compositionString += "Unit Cell Angles: {} {} {} (degrees in alpha,beta,gamma)\n".format(str(self.unitcell_alpha),str(self.unitcell_beta),str(self.unitcell_gamma))
compositionString += "Number of Residues: {}\n".format(str(self.numResidues))
compositionString += "Number of RNA: {}\n".format(str(self.numRNA))
compositionString += "Number of DNA: {}\n".format(str(self.numDNA))
compositionString += "Protein Heavy Atom number: {}\n".format(str(self.proteinHeavyAtoms))
compositionString += "Solvent Heavy Atom Concentration: {}\n".format(str(self.solventHeavyConc))
compositionString += "Solvent Fraction: {}\n".format(str(self.solventFraction))
compositionString += "Protein Concentration: {}\n".format(str(self.proteinConc))
return compositionString
class crystals_SAXSseqFile(crystals):
# A subclass for sequence file-defined SAXS crystal composition inputs
def __init__(self, crystName="", crystType="", crystDimX="", crystDimY="", crystDimZ="",
crystPixPerMic="", angleP="", angleL="", containerInfoDict={}, absCoefCalc="", modelFile="",
unitcell_a="", unitcell_b="", unitcell_c="",
unitcell_alpha="", unitcell_beta="", unitcell_gamma="",
proteinHeavyAtoms="", solventHeavyConc="",
solventFraction="", proteinConc="", sequenceFile=""):
super(crystals_SAXSseqFile, self).__init__(crystName, crystType, crystDimX, crystDimY, crystDimZ,
crystPixPerMic, angleP, angleL, containerInfoDict, absCoefCalc, modelFile)
self.unitcell_a = unitcell_a
self.unitcell_b = unitcell_b
self.unitcell_c = unitcell_c
self.unitcell_alpha = unitcell_alpha
self.unitcell_beta = unitcell_beta
self.unitcell_gamma = unitcell_gamma
self.proteinHeavyAtoms = proteinHeavyAtoms
self.solventHeavyConc = solventHeavyConc
self.solventFraction = solventFraction
self.proteinConc = proteinConc
self.seqFile = sequenceFile
def checkValidInputs_subclass(self):
ErrorMessage = ""
# check that unit cell dimensions can be converted to non-negative float format (from string format)
ErrorMessage += checks(self.unitcell_a,'unit cell a dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_b,'unit cell b dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_c,'unit cell c dimension',False).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_alpha,'unit cell angle alpha',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_beta,'unit cell angle beta',True).checkIfNonNegFloat()
ErrorMessage += checks(self.unitcell_gamma,'unit cell angle gamma',True).checkIfNonNegFloat()
# check that protein concentration can be converted to non-negative float format (from string)
ErrorMessage += checks(self.proteinConc,'protein concentration',False).checkIfNonNegFloat()
# check that crystal proteinHeavyAtoms formatting is correct
ErrorMessage += checks(self.proteinHeavyAtoms,'heavy atoms in protein',True).checkHeavyAtomFormat()
# check that crystal solventHeavyConc formatting is correct
ErrorMessage += checks(self.solventHeavyConc,'solvent heavy atom concentration',True).checkHeavyAtomFormat()
# check that solvent fraction is float between 0 and 1
ErrorMessage += checks(self.solventFraction,'solvent fraction',True).checkIfFloatBetween01()
# check that sequence file name has been entered
ErrorMessage += checks(self.seqFile,'sequence file',False).checkIfNonBlankString()
return ErrorMessage
def extractCrystalInfo_composition(self):
# create a string containing information of current crystal composition
compositionString = "\nComposition Information:\n"
compositionString += "Unit Cell Dimensions: {} {} {} (microns in a,b,c)\n".format(str(self.unitcell_a),str(self.unitcell_b),str(self.unitcell_c))
compositionString += "Unit Cell Angles: {} {} {} (degrees in alpha,beta,gamma)\n".format(str(self.unitcell_alpha),str(self.unitcell_beta),str(self.unitcell_gamma))
compositionString += "Protein Heavy Atom number: {}\n".format(str(self.proteinHeavyAtoms))
compositionString += "Solvent Heavy Atom Concenctration: {}\n".format(str(self.solventHeavyConc))
compositionString += "Solvent Fraction: {}\n".format(str(self.solventFraction))
compositionString += "Protein Concentration: {}\n".format(str(self.proteinConc))
compositionString += "Sequence File: {}\n".format(str(self.seqFile))
return compositionString