Graphics - Graphic plot for artificial with database support
use strict; use Chemistry::SQL; use Chemistry::Artificial::Graphics; my $dbname = $ARGV[0]; my $chaname = $ARGV[1]; my $file = $ARGV[2]; my $mode = $ARGV[3]; if (scalar(@ARGV)!=4) { print "Error in parameter number \n"; print "perl chaplot.pl DB_NAME CHA_NAME FILE_NAME MODE (svg | svg_static | text)\n"; exit; } my $db1 = Chemistry::SQL->new(db_host=>"127.0.0.1",db_user=>"root",db_port=>"3306",sb_pwd=>"",db_name=>"$dbname",db_driver=>"mysql"); $db1->connect_db; my $pcha = Chemistry::Artificial::Graphics->new(db => $db1, width=> "800",height=>"600",radius=> "10",distanceh=>"200",file=> $file, mode=> $mode); $pcha->ch_plot("$chaname");
This package, along with Chemistry::SQL, includes all the necessary to generate graphics of the artificial chemistry in database.
* db: Working database. * width: Width screen value. * height: Height screen value. * def_fathercolor: Components that have >=1 childs. * def_childcolor: Components that don't have any child. * def_font: Font name. * def_font_size: Font size in the graphic. * def_font_color: Font color in the graphic. * radius: Radius for each component (radius of the circle). * inix: This will be the first position X position. * iniy: This will be the first position Y position. * distanceh: Horitzontal distance from one component to each other. * id: First id component. * file: File name where we are going to save the graphic. * mode: Working mode (svg|svg_static|text).
Implements the methods.
Creates a new object graphics to plot artificial chemistry.
* Example:
my $pcha = Graphics->new(db => $db1,width=>"1400",height=>"1024", radius=>"10",distanceh=>"10",file=>"$file", mode=>"svg");
These functions are oriented to the generic I/O graphic file, and they are:
This function only creates the file where the graphic is going to be writed.
This function uses $self-{file>} parameter to set the name of the output file.
This function should be called from the inside of the module, not being recomended to call it from an external applicattion.
These are auxiliar functions used to work with components:
Returns 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);
These functions are used in the plot process.
These functions are used to write SVG files, and they are:
Here we define the style of the objects in the graph, for example: path (the lines), circle(the components), text (text properties)...
Here we defined the arrows directions too.
This function writes a component in the graph.
The properties: * id: This is an unique id for one component in the graph. * cx: X position.
Function used to write a text line in the SVG.
The properties: * x: X position to start the text. * y: Y positicion to start the text.
Function used to write a line in the SVG file. This is a path component of the SVG.
Title in english language.
SVG needs a header to be recongnized by browsers. This function puts the head in the SVG file.
These functions depend on the graphic type. The dynamic graphic need some diferent functions to work correctly.
This function writes the functions and header necessary for the SVG interaction.
ShowContentsAndRelatives(evt): This function tales the id of the current component and increments by one, the result is going to be the group that is associated at this component.
Each ball has a unique id, the child of one ball is in a group id+1.
Opens a new group in the SVG file.
Here if the group is the number 1 (root elements) then it is visible, else it is writted but is not visible.
Closes a group in the SVG file.
Writes the dynamic bottom (last lines) in the SVG file.
Here it is defined the option value (properties mode versus expand mode).
Plots a dinamic SVG grahic. This is the most sofisticated graphic that this module can produce.
Static graphics needs some diferent functions in the SVG file
Writes the bottom (last lines) in the SVG static file.
Represents a SVG static file with the solution in the solution graphic table.
How does it works:
Get all the root elements and then, get the childs for each one.
Text mode graphics needs diferent functions to write the file.
This function writes the title in the text version of the graphic
This function writes a txt file with the solution graph table. This is the simplest way to see a graphic structure of cha
These functions are used to plot and prepare the table before graphic drawing
These functions are used to work with specific artificial chemistry
Using Chemistry::SQL module store in the sgraph table the necessary data to draw the graphic of artificial chemistry (designed by name).
After this, plot using the apropiate function, it depends of the selected mode.
Example (Dynamic SVG):
my $cha5 = Graphics::new($db1,"1400","1024","10","10","25", "cha.svg","svg"); $cha5->ch_plot("$chaname");
Example (Static SVG):
my $cha6 = Graphics::new($db1,"1400","1024","10","10","25", "cha.svg","svg_static"); $cha6->ch_plot("$chaname");
Example (Text):
my $cha7 = Graphics::new($db1,"1400","1024","10","10","25", "cha.txt","text"); $cha7->ch_plot("$chaname");
Using Chemistry::SQL module store in the sgraph table the necessary data to draw the graphic of artificial chemistry (designed by name) from startlevel to endlevel.
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "chalevel.svg","svg"); $cha->ch_plot_levels("$chaname",2,3);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "chalevels.svg","svg_static"); $cha->ch_plot_levels("$chaname",2,3);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "chalevel.txt","text"); $cha->ch_plot_levels("$chaname",2,3);
These functions are used to work with especific results (components), and they are:
Using Chemistry::SQL module store in the sgraph table the necessary data to draw the possibilities from the start components in the Reference_Array
After this, draw using the apropiate function, it depends of the selected mode.
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fsc.svg","svg"); my @root; push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC1(CO)C(C(C(CO)O1)O)O)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1=CC=CC=C1C1=CC=CC=C1", format => 'smiles'); push @root,Chemistry:: Mol->parse("[O-]C1=CC=CC=C1C1=CC=CC=C1.[Na+]", format => 'smiles'); $cha->ch_plot_fsc(\@root);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fscs.svg","svg_static"); my @root; push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC1(CO)C(C(C(CO)O1)O)O)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1=CC=CC=C1C1=CC=CC=C1", format => 'smiles'); push @root,Chemistry::Mol-> parse("[O-]C1=CC=CC=C1C1=CC=CC=C1.[Na+]", format => 'smiles'); $cha->ch_plot_fsc(\@root);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fsc.txt","text"); my @root; push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC1(CO)C(C(C(CO)O1)O)O)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1C(C(C(CO)OC1OC)O)O", format => 'smiles'); push @root,Chemistry::Mol-> parse("OC1=CC=CC=C1C1=CC=CC=C1", format => 'smiles'); push @root,Chemistry::Mol-> parse("[O-]C1=CC=CC=C1C1=CC=CC=C1.[Na+]", format => 'smiles'); $cha->ch_plot_fsc(\@root);
Using Chemistry::SQL module store in the sgraph table the necessary data to draw from the end components in the Reference_Array
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fec.svg","svg"); my @root; push @root,Chemistry::Mol->parse("OC12C3C=CC4C5C6C=CC1(C35)C462", format => 'smiles'); push @root,Chemistry::Mol->parse("OC1C2C=CC3C=1C13C2C2C3C2C31", format => 'smiles'); $cha->ch_plot_fec(\@root);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fecs.svg","svg_static"); my @root; push @root,Chemistry::Mol->parse("OC12C3C=CC4C5C6C=CC1(C35)C462", format => 'smiles'); push @root,Chemistry::Mol->parse("OC1C2C=CC3C=1C13C2C2C3C2C31", format => 'smiles'); $cha->ch_plot_fec(\@root);
my $cha = Graphics::new($db1,"1400","1024","10","10","25", "gsg_fec.txt","text"); my @root; push @root,Chemistry::Mol->parse("OC12C3C=CC4C5C6C=CC1(C35)C462", format => 'smiles'); push @root,Chemistry::Mol->parse("OC1C2C=CC3C=1C13C2C2C3C2C31", format => 'smiles'); $cha->ch_plot_fec(\@root);
0.01
Chemistry::Artificial::SQL,Chemistry::SQL
The PerlMol website http://www.perlmol.org/
Bernat Requesens <brequesens@gmail.com>.
This program is free software; it can be redistributed and/or modified under the same terms as Perl itself.
To install Chemistry::Artificial::Graphics, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Chemistry::Artificial::Graphics
CPAN shell
perl -MCPAN -e shell install Chemistry::Artificial::Graphics
For more information on module installation, please visit the detailed CPAN module installation guide.