0
|
1 package MolecularDescriptors::Fsp3CarbonsDescriptors;
|
|
2 #
|
|
3 # $RCSfile: Fsp3CarbonsDescriptors.pm,v $
|
|
4 # $Date: 2015/02/28 20:49:19 $
|
|
5 # $Revision: 1.12 $
|
|
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 '""' => 'StringifyFsp3CarbonsDescriptors';
|
|
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->_InitializeFsp3CarbonsDescriptors();
|
|
62
|
|
63 $This->_InitializeFsp3CarbonsDescriptorsProperties(%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 = ('Fsp3Carbons', 'Sp3Carbons');
|
|
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 _InitializeFsp3CarbonsDescriptors {
|
|
90 my($This) = @_;
|
|
91
|
|
92 # Type of MolecularDescriptor...
|
|
93 $This->{Type} = 'Fsp3Carbons';
|
|
94
|
|
95 # Intialize descriptor names and values...
|
|
96 $This->_InitializeDescriptorNamesAndValues(@DescriptorNames);
|
|
97
|
|
98 return $This;
|
|
99 }
|
|
100
|
|
101 # Initialize object properties...
|
|
102 #
|
|
103 sub _InitializeFsp3CarbonsDescriptorsProperties {
|
|
104 my($This, %NamesAndValues) = @_;
|
|
105
|
|
106 my($Name, $Value, $MethodName);
|
|
107 while (($Name, $Value) = each %NamesAndValues) {
|
|
108 $MethodName = "Set${Name}";
|
|
109 $This->$MethodName($Value);
|
|
110 }
|
|
111
|
|
112 return $This;
|
|
113 }
|
|
114
|
|
115 # Calculate fraction of SP3 carbons (Fsp3Carbons) [ Ref 115-116, Ref 119 ] in a molecule...
|
|
116 #
|
|
117 # It is defined as follows:
|
|
118 #
|
|
119 # Fsp3 = Number of SP3 carbons/Total number of carbons
|
|
120 #
|
|
121 sub GenerateDescriptors {
|
|
122 my($This) = @_;
|
|
123
|
|
124 # Initialize descriptor values...
|
|
125 $This->_InitializeDescriptorValues();
|
|
126
|
|
127 # Check availability of molecule...
|
|
128 if (!$This->{Molecule}) {
|
|
129 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Molecule data is not available: Molecule object hasn't been set...";
|
|
130 return undef;
|
|
131 }
|
|
132
|
|
133 # Calculate descriptor values...
|
|
134 if (!$This->_CalculateDescriptorValues()) {
|
|
135 carp "Warning: ${ClassName}->GenerateDescriptors: $This->{Type} molecular descriptors generation didn't succeed: Couldn't calculate Fsp3Carbons values corresponding to assigned Fsp3Carbons atom types...";
|
|
136 return undef;
|
|
137 }
|
|
138
|
|
139 # Set final descriptor values...
|
|
140 $This->_SetFinalDescriptorValues();
|
|
141
|
|
142 return $This;
|
|
143 }
|
|
144
|
|
145 # Calculate Fsp3Carbons value...
|
|
146 #
|
|
147 sub _CalculateDescriptorValues {
|
|
148 my($This) = @_;
|
|
149 my($Atom, $AtomID, $TotalCarbons, $NumOfSp3Carbons, $Fsp3Carbons);
|
|
150
|
|
151 $TotalCarbons = 0;
|
|
152 $NumOfSp3Carbons = 0;
|
|
153
|
|
154 ATOM: for $Atom ($This->{Molecule}->GetAtoms()) {
|
|
155 if (!$Atom->IsCarbon()) {
|
|
156 next ATOM;
|
|
157 }
|
|
158 $TotalCarbons += 1;
|
|
159
|
|
160 if ($Atom->DoesAtomNeighborhoodMatch('C.T4.TSB4')) {
|
|
161 $NumOfSp3Carbons += 1;
|
|
162 }
|
|
163 }
|
|
164
|
|
165 $Fsp3Carbons = $NumOfSp3Carbons ? $NumOfSp3Carbons/$TotalCarbons : 0;
|
|
166
|
|
167 # Track values...
|
|
168 $This->{Fsp3Carbons} = MathUtil::round($Fsp3Carbons, 2);
|
|
169 $This->{Sp3Carbons} = $NumOfSp3Carbons;
|
|
170
|
|
171 return $This;
|
|
172 }
|
|
173
|
|
174 # Setup final descriptor values...
|
|
175 #
|
|
176 sub _SetFinalDescriptorValues {
|
|
177 my($This) = @_;
|
|
178
|
|
179 $This->{DescriptorsGenerated} = 1;
|
|
180
|
|
181 $This->SetDescriptorValues($This->{Fsp3Carbons}, $This->{Sp3Carbons});
|
|
182
|
|
183 return $This;
|
|
184 }
|
|
185
|
|
186 # Return a string containg data for Fsp3CarbonsDescriptors object...
|
|
187 #
|
|
188 sub StringifyFsp3CarbonsDescriptors {
|
|
189 my($This) = @_;
|
|
190 my($Fsp3CarbonsDescriptorsString);
|
|
191
|
|
192 $Fsp3CarbonsDescriptorsString = "MolecularDescriptorType: $This->{Type}; " . $This->_StringifyDescriptorNamesAndValues();
|
|
193
|
|
194 return $Fsp3CarbonsDescriptorsString;
|
|
195 }
|
|
196
|
|
197 # Is it a Fsp3CarbonsDescriptors object?
|
|
198 sub _IsFsp3CarbonsDescriptors {
|
|
199 my($Object) = @_;
|
|
200
|
|
201 return (Scalar::Util::blessed($Object) && $Object->isa($ClassName)) ? 1 : 0;
|
|
202 }
|
|
203
|
|
204 1;
|
|
205
|
|
206 __END__
|
|
207
|
|
208 =head1 NAME
|
|
209
|
|
210 Fsp3CarbonsDescriptors
|
|
211
|
|
212 =head1 SYNOPSIS
|
|
213
|
|
214 use MolecularDescriptors::Fsp3CarbonsDescriptors;
|
|
215
|
|
216 use MolecularDescriptors::Fsp3CarbonsDescriptors qw(:all);
|
|
217
|
|
218 =head1 DESCRIPTION
|
|
219
|
|
220 B<Fsp3CarbonsDescriptors> class provides the following methods:
|
|
221
|
|
222 new, GenerateDescriptors, GetDescriptorNames, StringifyFsp3CarbonsDescriptors
|
|
223
|
|
224 B<Fsp3CarbonsDescriptors> is derived from B<MolecularDescriptors> class which in turn
|
|
225 is derived from B<ObjectProperty> base class that provides methods not explicitly defined
|
|
226 in B<Fsp3CarbonsDescriptors>, B<MolecularDescriptors> or B<ObjectProperty> classes using Perl's
|
|
227 AUTOLOAD functionality. These methods are generated on-the-fly for a specified object property:
|
|
228
|
|
229 Set<PropertyName>(<PropertyValue>);
|
|
230 $PropertyValue = Get<PropertyName>();
|
|
231 Delete<PropertyName>();
|
|
232
|
|
233 Fraction sp3 carbons (Fsp3Carbons) [ Ref 115-116, Ref 119 ] value is calculated by dividing the number of sp3
|
|
234 carbons (Sp3Carbons) with the total number of carbons in a molecule.
|
|
235
|
|
236 =head2 METHODS
|
|
237
|
|
238 =over 4
|
|
239
|
|
240 =item B<new>
|
|
241
|
|
242 $NewFsp3CarbonsDescriptors = new MolecularDescriptors::
|
|
243 Fsp3CarbonsDescriptors(%NamesAndValues);
|
|
244
|
|
245 Using specified I<Fsp3CarbonsDescriptors> property names and values hash, B<new>
|
|
246 method creates a new object and returns a reference to newly created B<Fsp3CarbonsDescriptors>
|
|
247 object. By default, the following properties are initialized:
|
|
248
|
|
249 Molecule = ''
|
|
250 Type = 'Fsp3Carbons'
|
|
251 @DescriptorNames = ('Fsp3Carbons', 'Sp3Carbons')
|
|
252 @DescriptorValues = ('None', 'None')
|
|
253
|
|
254 Examples:
|
|
255
|
|
256 $Fsp3CarbonsDescriptors = new MolecularDescriptors::Fsp3CarbonsDescriptors(
|
|
257 'Molecule' => $Molecule);
|
|
258
|
|
259 $Fsp3CarbonsDescriptors = new MolecularDescriptors::Fsp3CarbonsDescriptors();
|
|
260
|
|
261 $Fsp3CarbonsDescriptors->SetMolecule($Molecule);
|
|
262 $Fsp3CarbonsDescriptors->GenerateDescriptors();
|
|
263 print "Fsp3CarbonsDescriptors: $Fsp3CarbonsDescriptors\n";
|
|
264
|
|
265 =item B<GenerateDescriptors>
|
|
266
|
|
267 $Fsp3CarbonsDescriptors->GenerateDescriptors();
|
|
268
|
|
269 Calculates Fsp3Carbons and Sp3Carbons values for a molecule and returns I<Fsp3CarbonsDescriptors>.
|
|
270
|
|
271 =item B<GetDescriptorNames>
|
|
272
|
|
273 @DescriptorNames = $Fsp3CarbonsDescriptors->GetDescriptorNames();
|
|
274 @DescriptorNames = MolecularDescriptors::Fsp3CarbonsDescriptors::
|
|
275 GetDescriptorNames();
|
|
276
|
|
277 Returns all available descriptor names as an array.
|
|
278
|
|
279 =item B<StringifyFsp3CarbonsDescriptors>
|
|
280
|
|
281 $String = $Fsp3CarbonsDescriptors->StringifyFsp3CarbonsDescriptors();
|
|
282
|
|
283 Returns a string containing information about I<Fsp3CarbonsDescriptors> object.
|
|
284
|
|
285 =back
|
|
286
|
|
287 =head1 AUTHOR
|
|
288
|
|
289 Manish Sud <msud@san.rr.com>
|
|
290
|
|
291 =head1 SEE ALSO
|
|
292
|
|
293 MolecularDescriptors.pm, MolecularDescriptorsGenerator.pm
|
|
294
|
|
295 =head1 COPYRIGHT
|
|
296
|
|
297 Copyright (C) 2015 Manish Sud. All rights reserved.
|
|
298
|
|
299 This file is part of MayaChemTools.
|
|
300
|
|
301 MayaChemTools is free software; you can redistribute it and/or modify it under
|
|
302 the terms of the GNU Lesser General Public License as published by the Free
|
|
303 Software Foundation; either version 3 of the License, or (at your option)
|
|
304 any later version.
|
|
305
|
|
306 =cut
|