Mercurial > repos > deepakjadmin > mayatool3_test2
comparison lib/MolecularDescriptors/WeightAndMassDescriptors.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::WeightAndMassDescriptors; | |
2 # | |
3 # $RCSfile: WeightAndMassDescriptors.pm,v $ | |
4 # $Date: 2015/02/28 20:49:20 $ | |
5 # $Revision: 1.10 $ | |
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 MolecularDescriptors::MolecularDescriptors; | |
38 | |
39 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | |
40 | |
41 @ISA = qw(MolecularDescriptors::MolecularDescriptors Exporter); | |
42 @EXPORT = qw(); | |
43 @EXPORT_OK = qw(GetDescriptorNames); | |
44 | |
45 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |
46 | |
47 # Setup class variables... | |
48 my($ClassName, @DescriptorNames); | |
49 _InitializeClass(); | |
50 | |
51 # Overload Perl functions... | |
52 use overload '""' => 'StringifyWeightAndMassDescriptors'; | |
53 | |
54 # Class constructor... | |
55 sub new { | |
56 my($Class, %NamesAndValues) = @_; | |
57 | |
58 # Initialize object... | |
59 my $This = $Class->SUPER::new(); | |
60 bless $This, ref($Class) || $Class; | |
61 $This->_InitializeWeightAndMassDescriptors(); | |
62 | |
63 $This->_InitializeWeightAndMassDescriptorsProperties(%NamesAndValues); | |
64 | |
65 return $This; | |
66 } | |
67 | |
68 # Initialize class ... | |
69 sub _InitializeClass { | |
70 #Class name... | |
71 $ClassName = __PACKAGE__; | |
72 | |
73 # Descriptor names... | |
74 @DescriptorNames = ('MolecularWeight', 'ExactMass'); | |
75 | |
76 } | |
77 | |
78 # Get descriptor names as an array. | |
79 # | |
80 # This functionality can be either invoked as a class function or an | |
81 # object method. | |
82 # | |
83 sub GetDescriptorNames { | |
84 return @DescriptorNames; | |
85 } | |
86 | |
87 # Initialize object data... | |
88 # | |
89 sub _InitializeWeightAndMassDescriptors { | |
90 my($This) = @_; | |
91 | |
92 # Type of MolecularDescriptor... | |
93 $This->{Type} = 'WeightAndMass'; | |
94 | |
95 # Precision for molecular weight and exact mass values... | |
96 $This->{WeightPrecision} = 2; | |
97 $This->{MassPrecision} = 4; | |
98 | |
99 # Intialize descriptor names and values... | |
100 $This->_InitializeDescriptorNamesAndValues(@DescriptorNames); | |
101 | |
102 return $This; | |
103 } | |
104 | |
105 # Initialize object properties... | |
106 # | |
107 sub _InitializeWeightAndMassDescriptorsProperties { | |
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 # Set weight precision for moelcular weight... | |
120 # | |
121 sub SetWeightPrecision { | |
122 my($This, $Value) = @_; | |
123 | |
124 if (!TextUtil::IsInteger($Value)) { | |
125 croak "Error: ${ClassName}->SetWeightPrecision: WeightPrecision value, $Value, is not valid: It must be a an integer..."; | |
126 } | |
127 $This->{WeightPrecision} = $Value; | |
128 | |
129 return $This; | |
130 } | |
131 | |
132 # Set mass precision for exact weight... | |
133 # | |
134 sub SetMassPrecision { | |
135 my($This, $Value) = @_; | |
136 | |
137 if (!TextUtil::IsInteger($Value)) { | |
138 croak "Error: ${ClassName}->SetMassPrecision: MassPrecision value, $Value, is not valid: It must be a an integer..."; | |
139 } | |
140 $This->{MassPrecision} = $Value; | |
141 | |
142 return $This; | |
143 } | |
144 | |
145 # Generate molecular weight and exact mass values... | |
146 # | |
147 sub GenerateDescriptors { | |
148 my($This) = @_; | |
149 | |
150 # Initialize descriptor values... | |
151 $This->_InitializeDescriptorValues(); | |
152 | |
153 # Check availability of molecule... | |
154 if (!$This->{Molecule}) { | |
155 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Molecule data is not available: Molecule object hasn't been set..."; | |
156 return undef; | |
157 } | |
158 | |
159 # Calculate descriptor values... | |
160 if (!$This->_CalculateDescriptorValues()) { | |
161 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed..."; | |
162 return undef; | |
163 } | |
164 | |
165 # Set final descriptor values... | |
166 $This->_SetFinalDescriptorValues(); | |
167 | |
168 return $This; | |
169 } | |
170 | |
171 # Calculate molecular weight and exact mass values.. | |
172 # | |
173 sub _CalculateDescriptorValues { | |
174 my($This) = @_; | |
175 my($MolecularWeight, $ExactMass); | |
176 | |
177 $MolecularWeight = $This->{Molecule}->GetMolecularWeight(); | |
178 $ExactMass = $This->{Molecule}->GetExactMass(); | |
179 | |
180 # Track values... | |
181 $This->{MolecularWeight} = MathUtil::round($MolecularWeight, $This->{WeightPrecision}); | |
182 $This->{ExactMass} = MathUtil::round($ExactMass, $This->{MassPrecision}); | |
183 | |
184 return $This; | |
185 } | |
186 | |
187 # Setup final descriptor values... | |
188 # | |
189 sub _SetFinalDescriptorValues { | |
190 my($This) = @_; | |
191 | |
192 $This->{DescriptorsGenerated} = 1; | |
193 | |
194 $This->SetDescriptorValues($This->{MolecularWeight}, $This->{ExactMass}); | |
195 | |
196 return $This; | |
197 } | |
198 | |
199 # Return a string containg data for WeightAndMassDescriptors object... | |
200 # | |
201 sub StringifyWeightAndMassDescriptors { | |
202 my($This) = @_; | |
203 my($TheString); | |
204 | |
205 $TheString = "MolecularDescriptorType: $This->{Type}; " . $This->_StringifyDescriptorNamesAndValues(); | |
206 | |
207 return $TheString; | |
208 } | |
209 | |
210 # Is it a WeightAndMassDescriptors object? | |
211 sub _IsWeightAndMassDescriptors { | |
212 my($Object) = @_; | |
213 | |
214 return (Scalar::Util::blessed($Object) && $Object->isa($ClassName)) ? 1 : 0; | |
215 } | |
216 | |
217 1; | |
218 | |
219 __END__ | |
220 | |
221 =head1 NAME | |
222 | |
223 WeightAndMassDescriptors | |
224 | |
225 =head1 SYNOPSIS | |
226 | |
227 use MolecularDescriptors::WeightAndMassDescriptors; | |
228 | |
229 use MolecularDescriptors::WeightAndMassDescriptors qw(:all); | |
230 | |
231 =head1 DESCRIPTION | |
232 | |
233 B<WeightAndMassDescriptors> class provides the following methods: | |
234 | |
235 new, GenerateDescriptors, GetDescriptorNames, StringifyWeightAndMassDescriptors | |
236 | |
237 B<WeightAndMassDescriptors> is derived from B<MolecularDescriptors> class which in turn | |
238 is derived from B<ObjectProperty> base class that provides methods not explicitly defined | |
239 in B<WeightAndMassDescriptors>, B<MolecularDescriptors> or B<ObjectProperty> classes using Perl's | |
240 AUTOLOAD functionality. These methods are generated on-the-fly for a specified object property: | |
241 | |
242 Set<PropertyName>(<PropertyValue>); | |
243 $PropertyValue = Get<PropertyName>(); | |
244 Delete<PropertyName>(); | |
245 | |
246 B<WeightAndMassDescriptors> calculates molecular weight and exact mass descriptors using | |
247 methods available in B<Molecule> class. | |
248 | |
249 =head2 METHODS | |
250 | |
251 =over 4 | |
252 | |
253 =item B<new> | |
254 | |
255 $NewWeightAndMassDescriptors = new MolecularDescriptors:: | |
256 WeightAndMassDescriptors( | |
257 %NamesAndValues); | |
258 | |
259 Using specified I<WeightAndMassDescriptors> property names and values hash, B<new> | |
260 method creates a new object and returns a reference to newly created B<WeightAndMassDescriptors> | |
261 object. By default, the following properties are initialized: | |
262 | |
263 Molecule = '' | |
264 Type = 'WeightAndMass' | |
265 WeightPrecision = 2; | |
266 MassPrecision = 4; | |
267 | |
268 @DescriptorNames = ('MolecularWeight', 'ExactMass') | |
269 @DescriptorValues = ('None', 'None') | |
270 | |
271 Examples: | |
272 | |
273 $WeightAndMassDescriptors = new MolecularDescriptors:: | |
274 WeightAndMassDescriptors( | |
275 'Molecule' => $Molecule); | |
276 | |
277 $WeightAndMassDescriptors = new MolecularDescriptors:: | |
278 WeightAndMassDescriptors(); | |
279 | |
280 $WeightAndMassDescriptors->SetMolecule($Molecule); | |
281 $WeightAndMassDescriptors->GenerateDescriptors(); | |
282 print "WeightAndMassDescriptors: $WeightAndMassDescriptors\n"; | |
283 | |
284 =item B<GenerateDescriptors> | |
285 | |
286 $WeightAndMassDescriptors->GenerateDescriptors(); | |
287 | |
288 Calculates molecular weight and exact mass of a molecule and returns | |
289 I<WeightAndMassDescriptors>. | |
290 | |
291 =item B<GetDescriptorNames> | |
292 | |
293 @DescriptorNames = $WeightAndMassDescriptors->GetDescriptorNames(); | |
294 @DescriptorNames = MolecularDescriptors::WeightAndMassDescriptors:: | |
295 GetDescriptorNames(); | |
296 | |
297 Returns all available descriptor names as an array. | |
298 | |
299 =item B<SetMassPrecision> | |
300 | |
301 $WeightAndMassDescriptors->SetMassPrecision($Precision); | |
302 | |
303 Sets precision for calculated exact mass value and returns | |
304 I<WeightAndMassDescriptors>. | |
305 | |
306 =item B<SetWeightPrecision> | |
307 | |
308 $WeightAndMassDescriptors->SetWeightPrecision($Precision); | |
309 | |
310 Sets precision for calculated molecular weight value and returns | |
311 I<WeightAndMassDescriptors>. | |
312 | |
313 =item B<StringifyWeightAndMassDescriptors> | |
314 | |
315 $String = $WeightAndMassDescriptors->StringifyWeightAndMassDescriptors(); | |
316 | |
317 Returns a string containing information about I<WeightAndMassDescriptors> object. | |
318 | |
319 =back | |
320 | |
321 =head1 AUTHOR | |
322 | |
323 Manish Sud <msud@san.rr.com> | |
324 | |
325 =head1 SEE ALSO | |
326 | |
327 MolecularDescriptors.pm, MolecularDescriptorsGenerator.pm | |
328 | |
329 =head1 COPYRIGHT | |
330 | |
331 Copyright (C) 2015 Manish Sud. All rights reserved. | |
332 | |
333 This file is part of MayaChemTools. | |
334 | |
335 MayaChemTools is free software; you can redistribute it and/or modify it under | |
336 the terms of the GNU Lesser General Public License as published by the Free | |
337 Software Foundation; either version 3 of the License, or (at your option) | |
338 any later version. | |
339 | |
340 =cut |