#!/usr/bin/perl #Atom.pm #Contains the methods for Atom, an object that represents an atom within a compound. package Atom; use base 'Class::Accessor::Faster'; use strict; #use warnings; #The following hashes to allow for conversion of mol file charge code to accepted numerical representations of charge and oxidation. my %SDF_charge_conversion = (2 => 2, 3 => 1, 4 => "Doublet Radical", 5 => -1, 6 => -2, 7 => -3, 0 => 0); my %SDF_oxidation_modification = (2 => 2, 3 => 1, 4 => 1, 5 => 1, 6 => 2, 7=> 3, 0 => 0); #Create prototypical atom object my @atom_fields = ( "element" => 0, #a string representing the element type of the atom "SDF_charge" => 0, #an integer representing the SDF_charge code of the atom "index" => 0, #an integer representing the index of the atom in the Atoms array of the molecule "bond_count" => 0, #an integer representing the number of bonds that contain the atom "bond_order_count" => 0, #an integer representing the sum of all bond orders of the bonds that contain the atom "oxidation_modifier" => 0, #an integer representing the oxidation state of the atom (calculated from charge) "charge" => 0, #an integer representing the charge of the atom (calculated from charge) ); Atom->mk_accessors( grep { $_ ne "0"; } (@atom_fields)); #Name: new #Description: Creates a new 'atom' object #Options: None #Input: @_ - @(element, SDF_charge, index, bond_count, bond_order_count, oxidation_modifier, charge) #Output: $self - Atom Object sub new { my $proto = shift @_; my $self = { @atom_fields, @_ }; $self = bless ($self, ref($proto) || $proto); $self->oxidation_modifier($SDF_oxidation_modification{$self->SDF_charge}); $self->charge($SDF_charge_conversion{$self->SDF_charge}); return $self; } 1;