The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

ArtificialSQL - Artificial chemistry with database support module

SYNOPSIS

    use strict;
    use Chemistry::SQL;
    use Chemistry::Artificial::SQL;
    
    # Execution: perl gcha.pl DBNAME CHANAME SIZE_VALUE LEVELS 
    # NUMBER_OF_COMPONENTS_TO_PROCESS
    
    my $dbname = $ARGV[0];
    my $chaname = $ARGV[1];
    my $size = $ARGV[2];
    my $levels = $ARGV[3];
    my $compnumber = $ARGV[4];
    
    if (scalar(@ARGV)!=5)
    { print "Incorrect parameter number  \n";
      print "perl gcha.pl DBNAME CHANAME SIZE_VALUE LEVELS 
      NUMBER_OF_COMPONENTS_TO_PROCESS \n";
      exit;
    }
    
    my $db1 = Chemistry::SQL->new(db_host=>"127.0.0.1",db_user=>"root",db_port=>"3306",db_pwd=>"",
    db_name=>"$dbname",db_driver=>"mysql");
    $db1->connect_db;
    
    my $cha = Chemistry::Artificial::SQL->new(db_name=>$db1);
    $cha->new_ch ("$chaname","TEST DESCRIPTION");
    
    
    #Inserting Reactions 
    #In this example file we're working with the reaction C=CC=C.C=C>>C1=CCCCC1
    my $string_react = $db1->string_react(1);
    my $qr=$cha->create_reaction($string_react,'smiles');
    $cha->art_insert_react($qr,"$chaname");
    my $string_react = $db1->string_react(2);
    my $qr=$cha->create_reaction($string_react,'smiles');
    $cha->art_insert_react($qr,"$chaname");
    
    # Inserting Components
    
    my $list = $db1->recover_comp("","");
    
    my $component;
    my $formula;
    my $smilesform;
    
    for (my $index=0; $index<$compnumber; $index++)
    {   @$list[$index]->print(format => 'smiles', unique => 1);
        $cha->art_insert_comp(@$list[$index],"$chaname");
    }
    print ("GENERATING $chaname IN $dbname DATABASE\n");
    $cha->ch_artificial_table($levels,"$chaname",$size);

DESCRIPTION

This package provides the necessary functions to work with the generation of artificial chemistry. The methods implemented in this package, are all oriented to generate artificial chemistry. There is a lot of interaction with the package Chemistry::SQL, but Chemistry::Artficial::SQL doesnt implement any Chemistry::SQL function.

Chemistry::Artificial::SQL Attributes

There is only one attribute necessary to work with this module.

        * db: This attribute describes the SQL object to use in the process.

METHODS

Methods of Chemistry::Artificial::SQL object.

Chemistry::Artificial::SQL->new(SQL_OBJECT)

Creates a new Chemistry::Articial::SQL object with the especified attributes.

Example:

        my $db1 = Chemistry::SQL->new(db_host=>"127.0.0.1",db_user=>"root",
        db_port=>"3306",db_pwd=>"",db_name=>"TESTDB",db_driver=>"mysql");
        $db1->connect_db;
        my $cha = Chemistry::Artificial::SQL->new(db_name => $db1);
        $cha->new_ch ("CHATEST","TEST DESCRIPTION");

Components functions

These are functions writed to make easier working with cha components

$cha->smiles_string($component)

Returns the SMILES format string of the component.

It is often used to get the SMILES string of the components in the function.

        $self->smiles_string($component);
$cha->art_insert_comp(component, qname)

When a new artificial chemistry is generated, all the components that will take part in this generation, are stored in the artifical chemistry table.

To insert a component in this table is necessary that the component exists in the components table. When a reaction is inserted in the artificial chemistry component, then the id of the component is stored in the table, but not all the information.

Reaction functions

These are functions writed to make easier working with reactions in the cha

$cha->create_reaction(reaction_string, type)

This function implements the creation of a new reaction from SMILES string.

There are some considerations about this function

- The reaction is created in a unique SMILES form.

- The function uses the Chemistry::Reaction module to create the final reaction.

Example:

        my $qr=$cha->create_reaction($string_react,'smiles');

string_react is a SMILESBEFORE >> SMILESAFTER format string.

$cha->art_insert_react(reaction, qname)

When a new artificial chemistry is generated, all the components that will take part in this generation, are stored in the artifical chemistry table.

To insert a reaction in this table, it is necessary that the reaction exists in the reaction table. When a reaction is inserted in the artificial chemistry reaction, then the id of the reaction is stored in the table, but not all the information.

Artificial Chemistry especific functions

These functions give control to create and generate artificial chemistry

$cha->new_ch(qname, description)

When a new ArtificialChemistry is created, the Chemistry::SQL module creates a new table with the qname name. This function is used to create a new artificial table.

Example:

        $cha->new_ch ("CHATEST","TEST DESCRIPTION");
cha->ch_next_level(Ref_array, qname, memsize, level)

Generates all the possible components in the next level. The components are in the database and Ref_array has all the reactions that we apply on one component.

How does it work:

- For each component all the reactions in the Ref_array are applied. If the interaction generates new components, then they are stored in the result table in the database.

- This function also is called from this module, is not recomended to call this function from external program. There is another function avaible that uses this one to generate the artifical chemistry.

- This function has direction support in the reaction application

$artificial->ch_artificial_table(levels, cha_name)

This function gets all the components and reactions into the artificial table and simulates an artificial chemistry. if levels is greater than 0, then the artificial simulation only generates the number of levels that are especified with this variable. If levels is minor than 0, the artificial simulation generates all levels of the artificial.

This method takes components of the level 0 (the components that exist in the artificial table) and make one level with all reactions in artificial table, and then take the next level and repeat the process levels level or while no results are discovered.

VERSION

0.01

SEE ALSO

Chemistry::SQL,Chemistry::Artificial::Graphics

The PerlMol website http://www.perlmol.org/

AUTHOR

Bernat Requesens <brequesens@gmail.com>.

COPYRIGHT

This program is free software; so it can be redistributed and/or modified under the same terms as Perl itself.