Friday, March 9, 2012

Perl: Variables and Functions

I have written Perl scripts for a long time (around 3 years?). However, since my programming style is so mixed: Perl, Matlab, C, Fortran, Mathematica, and their concept/syntax confuse me after not using it for some time. Here I summarize how the variables and functions are used.


Variables: Scalar, Arrays, Hash (not used much)

1. Scalar
    Define:  $variable
    Access:  $variable

2. Array
    Define:  @variable
    Access:  For each element, $variable[0]; to get the whole array @variable


Functions: define function, function input, function return

1. Define a Function: use sub to define, use & to call the function

#! /usr/bin/perl -w
use strict;

sub TestPrint{
    return "Test and Print\n";
}

&TestPrint;

2. Reference: similar as pointer in C, it is often used to pass value into/out of subroutine.




Subroutine take zero or more scalar arguments as input (and possibly output), and they return zero or one scalar as a return value.

2. Function Input: the @_ is input arguments, better to first convert it into private variables

#! /usr/bin/perl -w
use strict;

sub TestPrint {
   my($test1, @test2) = @_;
   my $test_print;

   foreach my $test_tmp (@test2) {
       $test_print .= "$test1, $test_tmp!\n";
   }

   print "$test_print\n";
}

my @name;

$name[0] = "Pan";
$name[1] = "Yue";
$name[2] = "TinTin";

&TestPrint("Hi", @name);
&TestPrint("Hi", "Pan", "Yue", "TinTin");


3. Function Return: return can be scaler, arrays or hash, better to use explicitly "return"







Wednesday, March 7, 2012

Electron Transfer: ET classification

My research is going to reach some of the ET reaction, so I need to understanding the following questions:
1) what is ET?
2) how many kind of ET exist?
3) what is the common theory?
4) what are the recent developments?

Here, I just summarize those information from wikipedia, IUPAC, about the ET definition and classification:

0) definition [from Wiki]: 
    Electron transfer (ET) is the process by which an electron moves from an atom or a chemical species (e.g. a molecule) to another atom or chemical species.

1) Inner-sphere electron transfer
    The two redox centers are covalently linked during the ET process.
        If the covalent linkage is transitory, it is intermolecular electron transfer
        If the covalent linkage is permanent, it is intramolecular electron transfer

     Another definition is:  the interaction between the donor and acceptor centres in the transition state is significant (>20 kJ/mol).

2) Outer-sphere electron transfer
    The participating redox centers are NOT linked via any bridge during the ET event.
        If two redox centers are SAME, it is called self-exchange reactions
        If two redox centers are DIFFERENT, it is called cross reactions

    A reaction in which the electron transfer takes place with no or very weak ( 4-16 kJ/mol ) electronic interaction between the reactants in the transition state.
    There are five steps in outer-sphere electron transfer: 
        1. reactants diffuse together out of their solvent shells => precursor complex (requires work =wr)
        2. changing bond lengths, reorganize solvent => activated complex
        3. Electron transfer
        4. Relaxation of bond lengths, solvent molecules => successor complex
        5. Diffusion of products (requires work=wp)