Mercurial > repos > deepakjadmin > mayatool3_test2
comparison lib/MolecularDescriptors/RingsCountDescriptors.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::RingsCountDescriptors; | |
| 2 # | |
| 3 # $RCSfile: RingsCountDescriptors.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 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 '""' => 'StringifyRingsCountDescriptors'; | |
| 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->_InitializeRingsCountDescriptors(); | |
| 59 | |
| 60 $This->_InitializeRingsCountDescriptorsProperties(%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 = ('Rings', 'AromaticRings'); | |
| 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 _InitializeRingsCountDescriptors { | |
| 87 my($This) = @_; | |
| 88 | |
| 89 # Type of MolecularDescriptor... | |
| 90 $This->{Type} = 'RingsCount'; | |
| 91 | |
| 92 # Intialize descriptor names and values... | |
| 93 $This->_InitializeDescriptorNamesAndValues(@DescriptorNames); | |
| 94 | |
| 95 return $This; | |
| 96 } | |
| 97 | |
| 98 # Initialize object properties... | |
| 99 # | |
| 100 sub _InitializeRingsCountDescriptorsProperties { | |
| 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->{Rings} = $This->{Molecule}->GetNumOfRings(); | |
| 145 $This->{AromaticRings} = $This->{Molecule}->GetNumOfAromaticRings(); | |
| 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->{Rings}, $This->{AromaticRings}); | |
| 158 | |
| 159 return $This; | |
| 160 } | |
| 161 | |
| 162 # Return a string containg data for RingsCountDescriptors object... | |
| 163 # | |
| 164 sub StringifyRingsCountDescriptors { | |
| 165 my($This) = @_; | |
| 166 my($TheString); | |
| 167 | |
| 168 $TheString = "MolecularDescriptorType: $This->{Type}; " . $This->_StringifyDescriptorNamesAndValues(); | |
| 169 | |
| 170 return $TheString; | |
| 171 } | |
| 172 | |
| 173 # Is it a RingsCountDescriptors object? | |
| 174 sub _IsRingsCountDescriptors { | |
| 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 RingsCountDescriptors | |
| 187 | |
| 188 =head1 SYNOPSIS | |
| 189 | |
| 190 use MolecularDescriptors::RingsCountDescriptors; | |
| 191 | |
| 192 use MolecularDescriptors::RingsCountDescriptors qw(:all); | |
| 193 | |
| 194 =head1 DESCRIPTION | |
| 195 | |
| 196 B<RingsCountDescriptors> class provides the following methods: | |
| 197 | |
| 198 new, GenerateDescriptors, GetDescriptorNames, StringifyRingsCountDescriptors | |
| 199 | |
| 200 B<RingsCountDescriptors> 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<RingsCountDescriptors>, 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<RingsCountDescriptors> class doesn't perform any ring or aromaticity detection before | |
| 210 counting their number in a molecule. Instead, it assumes ring and aromaticity detection have | |
| 211 been performed by caller using B<DetectRings> [Ref 31] and B<DetectAromaticity> methods | |
| 212 available in B<Molecule>. | |
| 213 | |
| 214 B<DetectAromaticity> method available in B<Molecule> class assigns aromaticity to rings | |
| 215 using Huckel rule as explained below: | |
| 216 | |
| 217 o Ring aromaticity is determined using Huckel's rule: a ring containing 4n + 2 pi electrons is | |
| 218 considered aromatic. | |
| 219 | |
| 220 o Hetrocyclic rings containing N, O and S atoms fall into two classes: Basic aromatic and | |
| 221 Non-basic aromatic. In Basic aromatic hetrocyclic rings, heteroatom itself is involved in a | |
| 222 double bond. (e.g. Pyridine) However, in non-basic hetrocyclic rings, heteroatom might have | |
| 223 an attached hydrogen atom and the remaining lone pair contribute to electron delocalization | |
| 224 and contributes to 4n + 2 electrons. (e.g. Pyrrole, Furan) | |
| 225 | |
| 226 o For molecules containing fused rings, each fused ring set is considered as one aromatic | |
| 227 system for counting pi electrons to satisfy Huckel's rule; In case of a failure, rings in | |
| 228 fused set are treated individually for aromaticity detection. Additionally, non-fused | |
| 229 rings are handled on their own during aromaticity detection. | |
| 230 | |
| 231 =head2 METHODS | |
| 232 | |
| 233 =over 4 | |
| 234 | |
| 235 =item B<new> | |
| 236 | |
| 237 $NewRingsCountDescriptors = new MolecularDescriptors:: | |
| 238 RingsCountDescriptors( | |
| 239 %NamesAndValues); | |
| 240 | |
| 241 Using specified I<RingsCountDescriptors> property names and values hash, B<new> | |
| 242 method creates a new object and returns a reference to newly created B<RingsCountDescriptors> | |
| 243 object. By default, the following properties are initialized: | |
| 244 | |
| 245 Molecule = '' | |
| 246 Type = 'RingsCount' | |
| 247 | |
| 248 @DescriptorNames = ('Rings', 'AromaticRings') | |
| 249 @DescriptorValues = ('None', 'None') | |
| 250 | |
| 251 Examples: | |
| 252 | |
| 253 $RingsCountDescriptors = new MolecularDescriptors::RingsCountDescriptors( | |
| 254 'Molecule' => $Molecule); | |
| 255 | |
| 256 $RingsCountDescriptors = new MolecularDescriptors::RingsCountDescriptors(); | |
| 257 | |
| 258 $RingsCountDescriptors->SetMolecule($Molecule); | |
| 259 $RingsCountDescriptors->GenerateDescriptors(); | |
| 260 print "RingsCountDescriptors: $RingsCountDescriptors\n"; | |
| 261 | |
| 262 =item B<GenerateDescriptors> | |
| 263 | |
| 264 $RingsCountDescriptors->GenerateDescriptors(); | |
| 265 | |
| 266 Calculate number of rings and aromatic rings in a molecule and returns | |
| 267 I<RingsCountDescriptors>. | |
| 268 | |
| 269 =item B<GetDescriptorNames> | |
| 270 | |
| 271 @DescriptorNames = $RingsCountDescriptors->GetDescriptorNames(); | |
| 272 @DescriptorNames = MolecularDescriptors::RingsCountDescriptors:: | |
| 273 GetDescriptorNames(); | |
| 274 | |
| 275 Returns all available descriptor names as an array. | |
| 276 | |
| 277 =item B<StringifyRingsCountDescriptors> | |
| 278 | |
| 279 $String = $RingsCountDescriptors-> | |
| 280 StringifyRingsCountDescriptors(); | |
| 281 | |
| 282 Returns a string containing information about I<RingsCountDescriptors> object. | |
| 283 | |
| 284 =back | |
| 285 | |
| 286 =head1 AUTHOR | |
| 287 | |
| 288 Manish Sud <msud@san.rr.com> | |
| 289 | |
| 290 =head1 SEE ALSO | |
| 291 | |
| 292 MolecularDescriptors.pm, MolecularDescriptorsGenerator.pm | |
| 293 | |
| 294 =head1 COPYRIGHT | |
| 295 | |
| 296 Copyright (C) 2015 Manish Sud. All rights reserved. | |
| 297 | |
| 298 This file is part of MayaChemTools. | |
| 299 | |
| 300 MayaChemTools is free software; you can redistribute it and/or modify it under | |
| 301 the terms of the GNU Lesser General Public License as published by the Free | |
| 302 Software Foundation; either version 3 of the License, or (at your option) | |
| 303 any later version. | |
| 304 | |
| 305 =cut |
