Mercurial > repos > deepakjadmin > mayatool3_test2
comparison lib/MolecularDescriptors/MolecularVolumeDescriptors.pm @ 0:4816e4a8ae95 draft default tip
Uploaded
author | deepakjadmin |
---|---|
date | Wed, 20 Jan 2016 09:23:18 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4816e4a8ae95 |
---|---|
1 package MolecularDescriptors::MolecularVolumeDescriptors; | |
2 # | |
3 # $RCSfile: MolecularVolumeDescriptors.pm,v $ | |
4 # $Date: 2015/02/28 20:49:20 $ | |
5 # $Revision: 1.16 $ | |
6 # | |
7 # Author: Manish Sud <msud@san.rr.com> | |
8 # | |
9 # Copyright (C) 2015 Manish Sud. All rights reserved. | |
10 # | |
11 # This file is part of MayaChemTools. | |
12 # | |
13 # MayaChemTools is free software; you can redistribute it and/or modify it under | |
14 # the terms of the GNU Lesser General Public License as published by the Free | |
15 # Software Foundation; either version 3 of the License, or (at your option) any | |
16 # later version. | |
17 # | |
18 # MayaChemTools is distributed in the hope that it will be useful, but without | |
19 # any warranty; without even the implied warranty of merchantability of fitness | |
20 # for a particular purpose. See the GNU Lesser General Public License for more | |
21 # details. | |
22 # | |
23 # You should have received a copy of the GNU Lesser General Public License | |
24 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or | |
25 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330, | |
26 # Boston, MA, 02111-1307, USA. | |
27 # | |
28 | |
29 use strict; | |
30 use Carp; | |
31 use Exporter; | |
32 use Scalar::Util (); | |
33 use TextUtil (); | |
34 use MathUtil (); | |
35 use Atom; | |
36 use Molecule; | |
37 use AtomTypes::AtomTypes; | |
38 use MolecularDescriptors::MolecularDescriptors; | |
39 | |
40 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | |
41 | |
42 @ISA = qw(MolecularDescriptors::MolecularDescriptors Exporter); | |
43 @EXPORT = qw(); | |
44 @EXPORT_OK = qw(GetDescriptorNames GetVDWAtomRadiiAndVolumesData); | |
45 | |
46 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |
47 | |
48 # Setup class variables... | |
49 my($ClassName, @DescriptorNames, %VDWAtomRadiiAndVolumesDataMap); | |
50 _InitializeClass(); | |
51 | |
52 # Overload Perl functions... | |
53 use overload '""' => 'StringifyMolecularVolumeDescriptors'; | |
54 | |
55 # Class constructor... | |
56 sub new { | |
57 my($Class, %NamesAndValues) = @_; | |
58 | |
59 # Initialize object... | |
60 my $This = $Class->SUPER::new(); | |
61 bless $This, ref($Class) || $Class; | |
62 $This->_InitializeMolecularVolumeDescriptors(); | |
63 | |
64 $This->_InitializeMolecularVolumeDescriptorsProperties(%NamesAndValues); | |
65 | |
66 return $This; | |
67 } | |
68 | |
69 # Initialize class ... | |
70 sub _InitializeClass { | |
71 #Class name... | |
72 $ClassName = __PACKAGE__; | |
73 | |
74 # Descriptor names... | |
75 @DescriptorNames = ('MolecularVolume'); | |
76 | |
77 # Initialize the data hash. It'll be loaded on demand later... | |
78 %VDWAtomRadiiAndVolumesDataMap = (); | |
79 | |
80 } | |
81 | |
82 # Get descriptor names as an array. | |
83 # | |
84 # This functionality can be either invoked as a class function or an | |
85 # object method. | |
86 # | |
87 sub GetDescriptorNames { | |
88 return @DescriptorNames; | |
89 } | |
90 | |
91 # Initialize object data... | |
92 # | |
93 sub _InitializeMolecularVolumeDescriptors { | |
94 my($This) = @_; | |
95 | |
96 # Type of MolecularDescriptor... | |
97 $This->{Type} = 'MolecularVolume'; | |
98 | |
99 # Intialize descriptor names and values... | |
100 $This->_InitializeDescriptorNamesAndValues(@DescriptorNames); | |
101 | |
102 return $This; | |
103 } | |
104 | |
105 # Initialize object properties... | |
106 # | |
107 sub _InitializeMolecularVolumeDescriptorsProperties { | |
108 my($This, %NamesAndValues) = @_; | |
109 | |
110 my($Name, $Value, $MethodName); | |
111 while (($Name, $Value) = each %NamesAndValues) { | |
112 $MethodName = "Set${Name}"; | |
113 $This->$MethodName($Value); | |
114 } | |
115 | |
116 return $This; | |
117 } | |
118 | |
119 # Get VDW atom data loaded from VDW atom radii and and volumes data file as | |
120 # a reference to hash with the following hash data format: | |
121 # | |
122 # @{$VDWAtomRadiiAndVolumesDataMap{AtomTypes}} - Array of all possible atom type symbols for all atoms | |
123 # @{$VDWAtomRadiiAndVolumesDataMap->{ColLabels}} - Array of column labels | |
124 # %{$VDWAtomRadiiAndVolumesDataMap->{DataCol<Num>}} - Hash keys pair: <DataCol<Num>, AtomType> | |
125 # | |
126 # This functionality can be either invoked as a class function or an | |
127 # object method. | |
128 # | |
129 sub GetVDWAtomRadiiAndVolumesData { | |
130 | |
131 # Make sure data is loaded... | |
132 _CheckAndLoadVDWAtomRadiiAndVolumesData(); | |
133 | |
134 return \%VDWAtomRadiiAndVolumesDataMap; | |
135 } | |
136 | |
137 # Calculate van der Waals molecular volume [ Ref 93 ] of a molecule using | |
138 # atomic and bonds contributions... | |
139 # | |
140 # van der Waals molecular volume (A**3/molecule) is defined as: | |
141 # | |
142 # vdwMolecularVolume = SumOfAtomicVDWVolumeContributions - 5.92 * NumOfBonds | |
143 # - 14.7 * NumOfAromaticRings - 3.8 * NumOfNonAromaticRings | |
144 # | |
145 # Methodology: | |
146 # . Add up van der Waals atom volumne of all atoms | |
147 # . Calculate molecular volume by correcting sum of atom volumes for num of | |
148 # bonds and rings | |
149 # | |
150 # Caveats: | |
151 # . All hydrogens must be added to molecule before calling GenerateDescriptors. | |
152 # | |
153 sub GenerateDescriptors { | |
154 my($This) = @_; | |
155 | |
156 # Initialize descriptor values... | |
157 $This->_InitializeDescriptorValues(); | |
158 | |
159 # Check availability of molecule... | |
160 if (!$This->{Molecule}) { | |
161 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Molecule data is not available: Molecule object hasn't been set..."; | |
162 return undef; | |
163 } | |
164 | |
165 # Calculate descriptor values... | |
166 if (!$This->_CalculateDescriptorValues()) { | |
167 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Couldn't calculate MolecularVolume values: van der Waals atom volume data is not available for all atoms..."; | |
168 return undef; | |
169 } | |
170 | |
171 # Set final descriptor values... | |
172 $This->_SetFinalDescriptorValues(); | |
173 | |
174 return $This; | |
175 } | |
176 | |
177 # Calculate MolecularVolume value... | |
178 # | |
179 sub _CalculateDescriptorValues { | |
180 my($This) = @_; | |
181 my($Atom, $AtomID, $AtomSymbol, $SumOfVDWAtomVolumes, $Molecule, $MolecularVolume, $NumOfBonds, $NumOfAromaticRings, $NumOfNonAromaticRings, $VDWAtomRadiiAndVolumesDataMapRef); | |
182 | |
183 $MolecularVolume = 0; | |
184 | |
185 $VDWAtomRadiiAndVolumesDataMapRef = $This->GetVDWAtomRadiiAndVolumesData(); | |
186 $Molecule = $This->{Molecule}; | |
187 | |
188 # Calculate atom volumes contribution to molecular volume... | |
189 # | |
190 $SumOfVDWAtomVolumes = 0; | |
191 | |
192 ATOM: for $Atom ($Molecule->GetAtoms()) { | |
193 $AtomID = $Atom->GetID(); | |
194 $AtomSymbol = $Atom->GetAtomSymbol(); | |
195 | |
196 # Make sure van der Waals atom volume is available... | |
197 if (!exists $VDWAtomRadiiAndVolumesDataMap{DataCol3}{$AtomSymbol}) { | |
198 return undef; | |
199 } | |
200 $SumOfVDWAtomVolumes += $VDWAtomRadiiAndVolumesDataMapRef->{DataCol3}{$AtomSymbol}; | |
201 } | |
202 | |
203 $NumOfBonds = $Molecule->GetNumOfBonds(); | |
204 $NumOfAromaticRings = $Molecule->GetNumOfAromaticRings(); | |
205 $NumOfNonAromaticRings = $Molecule->GetNumOfRings() - $NumOfAromaticRings; | |
206 | |
207 # Apply correction for bonds and rings... | |
208 $MolecularVolume = $SumOfVDWAtomVolumes - 5.92 * $NumOfBonds - 14.7 * $NumOfAromaticRings - 3.8 * $NumOfNonAromaticRings; | |
209 | |
210 # Track the calculated values... | |
211 $This->{MolecularVolume} = MathUtil::round($MolecularVolume, 2); | |
212 | |
213 return $This; | |
214 } | |
215 | |
216 # Setup final descriptor values... | |
217 # | |
218 sub _SetFinalDescriptorValues { | |
219 my($This) = @_; | |
220 | |
221 $This->{DescriptorsGenerated} = 1; | |
222 | |
223 $This->SetDescriptorValues($This->{MolecularVolume}); | |
224 | |
225 return $This; | |
226 } | |
227 | |
228 # Return a string containg data for MolecularVolumeDescriptors object... | |
229 # | |
230 sub StringifyMolecularVolumeDescriptors { | |
231 my($This) = @_; | |
232 my($MolecularVolumeDescriptorsString); | |
233 | |
234 $MolecularVolumeDescriptorsString = "MolecularDescriptorType: $This->{Type}; " . $This->_StringifyDescriptorNamesAndValues(); | |
235 | |
236 return $MolecularVolumeDescriptorsString; | |
237 } | |
238 | |
239 # Is it a MolecularVolumeDescriptors object? | |
240 sub _IsMolecularVolumeDescriptors { | |
241 my($Object) = @_; | |
242 | |
243 return (Scalar::Util::blessed($Object) && $Object->isa($ClassName)) ? 1 : 0; | |
244 } | |
245 | |
246 # Check and load van der Waals atom radii and volumes data... | |
247 # | |
248 sub _CheckAndLoadVDWAtomRadiiAndVolumesData { | |
249 | |
250 # Is it already loaded? | |
251 if (exists $VDWAtomRadiiAndVolumesDataMap{AtomTypes}) { | |
252 return; | |
253 } | |
254 | |
255 _LoadVDWAtomRadiiAndVolumesData(); | |
256 } | |
257 | |
258 # Initialize van der Waals atom radii and volumes data from the file... | |
259 # | |
260 # Format: | |
261 # | |
262 # "AtomTypeSymbol","VDWAtomRadius(A)","VDWAtomVolume(A**3)/molecule" | |
263 # "H","1.20","7.24" | |
264 # "He","1.40","11.49" | |
265 # | |
266 sub _LoadVDWAtomRadiiAndVolumesData { | |
267 my($VDWAtomDataFile, $MayaChemToolsLibDir); | |
268 | |
269 $MayaChemToolsLibDir = FileUtil::GetMayaChemToolsLibDirName(); | |
270 | |
271 $VDWAtomDataFile = "$MayaChemToolsLibDir" . "/data/VDWAtomRadiiAndVolumes.csv"; | |
272 if (! -e "$VDWAtomDataFile") { | |
273 croak "Error: MayaChemTools package file, $VDWAtomDataFile, is missing: Possible installation problems..."; | |
274 } | |
275 | |
276 %VDWAtomRadiiAndVolumesDataMap = (); | |
277 AtomTypes::AtomTypes::LoadAtomTypesData($VDWAtomDataFile, \%VDWAtomRadiiAndVolumesDataMap); | |
278 }; | |
279 | |
280 1; | |
281 | |
282 __END__ | |
283 | |
284 =head1 NAME | |
285 | |
286 MolecularVolumeDescriptors | |
287 | |
288 =head1 SYNOPSIS | |
289 | |
290 use MolecularDescriptors::MolecularVolumeDescriptors; | |
291 | |
292 use MolecularDescriptors::MolecularVolumeDescriptors qw(:all); | |
293 | |
294 =head1 DESCRIPTION | |
295 | |
296 B<MolecularVolumeDescriptors> class provides the following methods: | |
297 | |
298 new, GenerateDescriptors, GetDescriptorNames, | |
299 GetVDWAtomRadiiAndVolumesData, StringifyMolecularVolumeDescriptors | |
300 | |
301 B<MolecularVolumeDescriptors> is derived from B<MolecularDescriptors> class which in turn | |
302 is derived from B<ObjectProperty> base class that provides methods not explicitly defined | |
303 in B<MolecularVolumeDescriptors>, B<MolecularDescriptors> or B<ObjectProperty> classes using Perl's | |
304 AUTOLOAD functionality. These methods are generated on-the-fly for a specified object property: | |
305 | |
306 Set<PropertyName>(<PropertyValue>); | |
307 $PropertyValue = Get<PropertyName>(); | |
308 Delete<PropertyName>(); | |
309 | |
310 van der Waals molecular volume [ Ref 93 ] (A**3/molecule) of a molecule is | |
311 calculated using atomic and bonds contributions along with adjustments for | |
312 aromatic and non-aromatic rings using the following equation: | |
313 | |
314 vdwMolecularVolume = SumOfAtomicVDWVolumeContributions | |
315 - 5.92 * NumOfBonds | |
316 - 14.7 * NumOfAromaticRings | |
317 - 3.8 * NumOfNonAromaticRings | |
318 | |
319 van der Waals atomic volume for atoms is taken from data file VDWAtomRadiiAndVolumes.csv | |
320 distributed with MayaChemTools. It contains van der Waals atom radii and atom and volumes | |
321 data for 38 elements; Table 2 [ Ref 93 ] contains data for only 15 elements. After converting | |
322 valid van der Waals atom radius data from pm (picometer) to A (Angstrom) available under column | |
323 name VanderWaalsRadius in PeriodicTableElementsData.csv data file, van der Waals atom volume | |
324 is calculated using: 4/3 * PI * (Radius ** 3). For elements specified in Table 2 [ Ref 93 ] - | |
325 H, B, C, N, O, F, Si, P, S, Cl, As, Se, Br, Te, I - the van der Waals atom radii and calculated | |
326 atom volumes match the values in the table. | |
327 | |
328 =head2 METHODS | |
329 | |
330 =over 4 | |
331 | |
332 =item B<new> | |
333 | |
334 $NewMolecularVolumeDescriptors = new MolecularDescriptors:: | |
335 MolecularVolumeDescriptors( | |
336 %NamesAndValues); | |
337 | |
338 Using specified I<MolecularVolumeDescriptors> property names and values hash, B<new> | |
339 method creates a new object and returns a reference to newly created B<MolecularVolumeDescriptors> | |
340 object. By default, the following properties are initialized: | |
341 | |
342 Molecule = '' | |
343 Type = 'MolecularVolume' | |
344 @DescriptorNames = ('MolecularVolume') | |
345 @DescriptorValues = ('None') | |
346 | |
347 Examples: | |
348 | |
349 $MolecularVolumeDescriptors = new MolecularDescriptors:: | |
350 MolecularVolumeDescriptors(); | |
351 | |
352 $MolecularVolumeDescriptors->SetMolecule($Molecule); | |
353 $MolecularVolumeDescriptors->GenerateDescriptors(); | |
354 print "MolecularVolumeDescriptors: $MolecularVolumeDescriptors\n"; | |
355 | |
356 =item B<GenerateDescriptors> | |
357 | |
358 $MolecularVolumeDescriptors->GenerateDescriptors(); | |
359 | |
360 Calculate van der Waals molecular volume descriptor for a molecule and returns | |
361 I<MolecularVolumeDescriptors>. | |
362 | |
363 =item B<GetDescriptorNames> | |
364 | |
365 @DescriptorNames = $MolecularVolumeDescriptors->GetDescriptorNames(); | |
366 @DescriptorNames = MolecularDescriptors::MolecularVolumeDescriptors:: | |
367 GetDescriptorNames(); | |
368 | |
369 Returns all available descriptor names as an array. | |
370 | |
371 =item B<GetVDWAtomRadiiAndVolumesData> | |
372 | |
373 $VDWVolumeDataMapRef = $MolecularVolumeDescriptors-> | |
374 GetVDWAtomRadiiAndVolumesData(); | |
375 $VDWVolumeDataMapRef = MolecularDescriptors::MolecularVolumeDescriptors:: | |
376 GetVDWAtomRadiiAndVolumesData(); | |
377 | |
378 Returns a hash reference to van der Waals atom symbols corresponding to atom types | |
379 and associated data loaded from VDWAtomRadiiAndVolumes.csv data file as a reference | |
380 to hash with the following hash data format: | |
381 | |
382 @{$VDWVolumeDataMap{AtomTypes}} - Array of all possible atom | |
383 types for all atom symbols | |
384 @{$VDWVolumeDataMap->{ColLabels}} - Array of column labels | |
385 %{$VDWVolumeDataMap->{DataCol<Num>}} - Hash keys pair: | |
386 DataCol<Num>, AtomType | |
387 | |
388 =item B<StringifyMolecularVolumeDescriptors> | |
389 | |
390 $String = $MolecularVolumeDescriptors-> | |
391 StringifyMolecularVolumeDescriptors(); | |
392 | |
393 Returns a string containing information about I<MolecularVolumeDescriptors> object. | |
394 | |
395 =back | |
396 | |
397 =head1 AUTHOR | |
398 | |
399 Manish Sud <msud@san.rr.com> | |
400 | |
401 =head1 SEE ALSO | |
402 | |
403 MolecularDescriptors.pm, MolecularDescriptorsGenerator.pm | |
404 | |
405 =head1 COPYRIGHT | |
406 | |
407 Copyright (C) 2015 Manish Sud. All rights reserved. | |
408 | |
409 This file is part of MayaChemTools. | |
410 | |
411 MayaChemTools is free software; you can redistribute it and/or modify it under | |
412 the terms of the GNU Lesser General Public License as published by the Free | |
413 Software Foundation; either version 3 of the License, or (at your option) | |
414 any later version. | |
415 | |
416 =cut |