package Molecule;

use Geometry;

sub new {
	my $class = shift;
	$self = { 
		id => "", 
		atoms => [], 
		charge => 0.0, 
		mw => 0.0,
		connect => [],
		numAtoms => 0
		};
}

sub id {
	my ($self, $id) = @_;
	$self->{id} = $id if defined $id;
	return $self->{id};
}

sub charge {
	my $self = @_;
	return $self->{charge};
}

sub getCharge {
	my $self = shift;
	$self->{charge}= 0.0;
	for my $at  (@{$self->{atoms}}) {
		$self->{charge} += $at->charge;
	}
	return $self->{charge};
}
 

sub addAtom {
	my ($self, $atom) = @_;
	push @($self->{atoms}), $atom;
	$self->{charge} += $atom->charge;
	$self->{numAtoms}++;
	$self->{mw} += $atom->mw;
	for (my $i=0; $i < $self->{numAtoms}; $i++) {
		$self->{connect}->[$i][$self->{numAtoms}-1] = 0;
		$self->{connect}->[$self->{numAtoms}-1][$i] = 0;
	};
	return $self;
};

sub atoms {
	my $self = shift;
	return $self->{atoms};
};

sub numAtoms {
	my $self = shift;
	return scalar @{$self->{atoms}};
}

sub connectByDist {
	my $self = shift;
	for (my $i=0; $i < $self->{numAtoms} - 1; $i++) {
		for (my $j=$i+1; $j < $self->{numAtoms}; $j++) {
			my $dist = Geometry::calcDist (
				$self->{atoms}->[$i]->xyz,
				$self->{atoms}->{$j}->xyz);
			if ($dist < $BONDCUTOFF) {
				$self->{connect}->[$i][$j] = 1;
				$self->{connect}->[$j][$i] = 1;
			};
		}
	}
}
				
					
	 
