0
|
1 package MolecularDescriptors::AtomsCountDescriptors;
|
|
2 #
|
|
3 # $RCSfile: AtomsCountDescriptors.pm,v $
|
|
4 # $Date: 2015/02/28 20:49:19 $
|
|
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 Molecule;
|
|
34 use MolecularDescriptors::MolecularDescriptors;
|
|
35
|
|
36 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
|
37
|
|
38 @ISA = qw(MolecularDescriptors::MolecularDescriptors Exporter);
|
|
39 @EXPORT = qw();
|
|
40 @EXPORT_OK = qw(GetDescriptorNames);
|
|
41
|
|
42 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
|
|
43
|
|
44 # Setup class variables...
|
|
45 my($ClassName, @DescriptorNames);
|
|
46 _InitializeClass();
|
|
47
|
|
48 # Overload Perl functions...
|
|
49 use overload '""' => 'StringifyAtomsCountDescriptors';
|
|
50
|
|
51 # Class constructor...
|
|
52 sub new {
|
|
53 my($Class, %NamesAndValues) = @_;
|
|
54
|
|
55 # Initialize object...
|
|
56 my $This = $Class->SUPER::new();
|
|
57 bless $This, ref($Class) || $Class;
|
|
58 $This->_InitializeAtomsCountDescriptors();
|
|
59
|
|
60 $This->_InitializeAtomsCountDescriptorsProperties(%NamesAndValues);
|
|
61
|
|
62 return $This;
|
|
63 }
|
|
64
|
|
65 # Initialize class ...
|
|
66 sub _InitializeClass {
|
|
67 #Class name...
|
|
68 $ClassName = __PACKAGE__;
|
|
69
|
|
70 # Descriptor names...
|
|
71 @DescriptorNames = ('Atoms', 'HeavyAtoms');
|
|
72
|
|
73 }
|
|
74
|
|
75 # Get descriptor names as an array...
|
|
76 #
|
|
77 # This functionality can be either invoked as a class function or an
|
|
78 # object method.
|
|
79 #
|
|
80 sub GetDescriptorNames {
|
|
81 return @DescriptorNames;
|
|
82 }
|
|
83
|
|
84 # Initialize object data...
|
|
85 #
|
|
86 sub _InitializeAtomsCountDescriptors {
|
|
87 my($This) = @_;
|
|
88
|
|
89 # Type of MolecularDescriptor...
|
|
90 $This->{Type} = 'AtomsCount';
|
|
91
|
|
92 # Intialize descriptor names and values...
|
|
93 $This->_InitializeDescriptorNamesAndValues(@DescriptorNames);
|
|
94
|
|
95 return $This;
|
|
96 }
|
|
97
|
|
98 # Initialize object properties...
|
|
99 #
|
|
100 sub _InitializeAtomsCountDescriptorsProperties {
|
|
101 my($This, %NamesAndValues) = @_;
|
|
102
|
|
103 my($Name, $Value, $MethodName);
|
|
104 while (($Name, $Value) = each %NamesAndValues) {
|
|
105 $MethodName = "Set${Name}";
|
|
106 $This->$MethodName($Value);
|
|
107 }
|
|
108
|
|
109 return $This;
|
|
110 }
|
|
111
|
|
112 # Generate molecular weight and exact mass values...
|
|
113 #
|
|
114 sub GenerateDescriptors {
|
|
115 my($This) = @_;
|
|
116
|
|
117 # Initialize descriptor values...
|
|
118 $This->_InitializeDescriptorValues();
|
|
119
|
|
120 # Check availability of molecule...
|
|
121 if (!$This->{Molecule}) {
|
|
122 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Molecule data is not available: Molecule object hasn't been set...";
|
|
123 return undef;
|
|
124 }
|
|
125
|
|
126 # Calculate descriptor values...
|
|
127 if (!$This->_CalculateDescriptorValues()) {
|
|
128 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed...";
|
|
129 return undef;
|
|
130 }
|
|
131
|
|
132 # Set final descriptor values...
|
|
133 $This->_SetFinalDescriptorValues();
|
|
134
|
|
135 return $This;
|
|
136 }
|
|
137
|
|
138 # Calculate molecular weight and exact mass values..
|
|
139 #
|
|
140 sub _CalculateDescriptorValues {
|
|
141 my($This) = @_;
|
|
142 my($MolecularWeight, $ExactMass);
|
|
143
|
|
144 $This->{Atoms} = $This->{Molecule}->GetNumOfAtoms();
|
|
145 $This->{HeavyAtoms} = $This->{Molecule}->GetNumOfHeavyAtoms();
|
|
146
|
|
147 return $This;
|
|
148 }
|
|
149
|
|
150 # Setup final descriptor values...
|
|
151 #
|
|
152 sub _SetFinalDescriptorValues {
|
|
153 my($This) = @_;
|
|
154
|
|
155 $This->{DescriptorsGenerated} = 1;
|
|
156
|
|
157 $This->SetDescriptorValues($This->{Atoms}, $This->{HeavyAtoms});
|
|
158
|
|
159 return $This;
|
|
160 }
|
|
161
|
|
162 # Return a string containg data for AtomsCountDescriptors object...
|
|
163 #
|
|
164 sub StringifyAtomsCountDescriptors {
|
|
165 my($This) = @_;
|
|
166 my($TheString);
|
|
167
|
|
168 $TheString = "MolecularDescriptorType: $This->{Type}; " . $This->_StringifyDescriptorNamesAndValues();
|
|
169
|
|
170 return $TheString;
|
|
171 }
|
|
172
|
|
173 # Is it a AtomsCountDescriptors object?
|
|
174 sub _IsAtomsCountDescriptors {
|
|
175 my($Object) = @_;
|
|
176
|
|
177 return (Scalar::Util::blessed($Object) && $Object->isa($ClassName)) ? 1 : 0;
|
|
178 }
|
|
179
|
|
180 1;
|
|
181
|
|
182 __END__
|
|
183
|
|
184 =head1 NAME
|
|
185
|
|
186 AtomsCountDescriptors
|
|
187
|
|
188 =head1 SYNOPSIS
|
|
189
|
|
190 use MolecularDescriptors::AtomsCountDescriptors;
|
|
191
|
|
192 use MolecularDescriptors::AtomsCountDescriptors qw(:all);
|
|
193
|
|
194 =head1 DESCRIPTION
|
|
195
|
|
196 B<AtomsCountDescriptors> class provides the following methods:
|
|
197
|
|
198 new, GenerateDescriptors, GetDescriptorNames, StringifyAtomsCountDescriptors
|
|
199
|
|
200 B<AtomsCountDescriptors> is derived from B<MolecularDescriptors> class which in turn
|
|
201 is derived from B<ObjectProperty> base class that provides methods not explicitly defined
|
|
202 in B<AtomsCountDescriptors>, B<MolecularDescriptors> or B<ObjectProperty> classes using Perl's
|
|
203 AUTOLOAD functionality. These methods are generated on-the-fly for a specified object property:
|
|
204
|
|
205 Set<PropertyName>(<PropertyValue>);
|
|
206 $PropertyValue = Get<PropertyName>();
|
|
207 Delete<PropertyName>();
|
|
208
|
|
209 B<AtomsCountDescriptors> class counts the number of atoms and heavy atoms in a molecule
|
|
210 corresponding to total number of atom and non-hydrogen atoms respectively.
|
|
211
|
|
212 =head2 METHODS
|
|
213
|
|
214 =over 4
|
|
215
|
|
216 =item B<new>
|
|
217
|
|
218 $NewAtomsCountDescriptors = new MolecularDescriptors::
|
|
219 AtomsCountDescriptors(
|
|
220 %NamesAndValues);
|
|
221
|
|
222 Using specified I<AtomsCountDescriptors> property names and values hash, B<new>
|
|
223 method creates a new object and returns a reference to newly created B<AtomsCountDescriptors>
|
|
224 object. By default, the following properties are initialized:
|
|
225
|
|
226 Molecule = ''
|
|
227 Type = 'AtomsCount'
|
|
228
|
|
229 @DescriptorNames = ('Atoms', 'HeavyAtoms')
|
|
230 @DescriptorValues = ('None', 'None')
|
|
231
|
|
232 Examples:
|
|
233
|
|
234 $AtomsCountDescriptors = new AtomsCountDescriptors(
|
|
235 'Molecule' => $Molecule);
|
|
236
|
|
237 $AtomsCountDescriptors = new AtomsCountDescriptors();
|
|
238
|
|
239 $AtomsCountDescriptors->SetMolecule($Molecule);
|
|
240 $AtomsCountDescriptors->GenerateDescriptors();
|
|
241 print "AtomsCountDescriptors: $AtomsCountDescriptors\n";
|
|
242
|
|
243
|
|
244 =item B<GenerateDescriptors>
|
|
245
|
|
246 $AtomsCountDescriptors->GenerateDescriptors();
|
|
247
|
|
248 Calculates number of atoms and heavy atoms in a molecule and returns I<AtomsCountDescriptors>.
|
|
249
|
|
250 =item B<GetDescriptorNames>
|
|
251
|
|
252 @DescriptorNames = $AtomsCountDescriptors->GetDescriptorNames();
|
|
253 @DescriptorNames = MolecularDescriptors::AtomsCountDescriptors::
|
|
254 GetDescriptorNames();
|
|
255
|
|
256 Returns all available descriptor names as an array.
|
|
257
|
|
258 =item B<StringifyAtomsCountDescriptors>
|
|
259
|
|
260 $String = $AtomsCountDescriptors->StringifyAtomsCountDescriptors();
|
|
261
|
|
262 Returns a string containing information about I<AtomsCountDescriptors> object.
|
|
263
|
|
264 =back
|
|
265
|
|
266 =head1 AUTHOR
|
|
267
|
|
268 Manish Sud <msud@san.rr.com>
|
|
269
|
|
270 =head1 SEE ALSO
|
|
271
|
|
272 MolecularDescriptors.pm, MolecularDescriptorsGenerator.pm
|
|
273
|
|
274 =head1 COPYRIGHT
|
|
275
|
|
276 Copyright (C) 2015 Manish Sud. All rights reserved.
|
|
277
|
|
278 This file is part of MayaChemTools.
|
|
279
|
|
280 MayaChemTools is free software; you can redistribute it and/or modify it under
|
|
281 the terms of the GNU Lesser General Public License as published by the Free
|
|
282 Software Foundation; either version 3 of the License, or (at your option)
|
|
283 any later version.
|
|
284
|
|
285 =cut
|