Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Koverda committed Feb 25, 2019
1 parent 023fbb0 commit da00181
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 48 deletions.
Binary file modified Guide_EN.pdf
Binary file not shown.
Binary file modified Guide_RU.pdf
Binary file not shown.
84 changes: 57 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The program calculates the minimum (*Ix*) and maximum (*Iz*) moments of inertia

## System requirements

For normal operation of the program, at least 2Gb of RAM is required. However, when calculating large molecules (more than 30 atoms), the recommended amount of RAM is 8 Gb.
For normal operation of the program, at least 2 Gb of RAM is required. However, when calculating large molecules (more than 30 atoms), the recommended amount of RAM is 4 Gb.

## Software requirements

Expand All @@ -18,14 +18,31 @@ To use the program, run it in the shell with the location of the XYZ file, for e
$ ./moments_of_inertia.pl filename.xyz
```

The program will create a text file *filename.xyz.txt* with the results of the calculation in the directory where the file *filename.xyz* is located. Examples of source XYZ files can be found in the *Examples* folder. For example, launching the program with the file *Pyridine.xyz* will create the file *Pyridine.xyz.txt* with the results of the calculation:
The program will create a text file *filename.txt* with the results of the calculation in the directory where the file *filename.xyz* is located. Examples of source XYZ files can be found in the *Examples* folder. For example, launching the program with the file *Pentane.xyz* will create the file *Pentane.txt* with the results of the calculation:

```
Calculation for data from file ./Pyridine.xyz
The calculation with step of the directing vector is 0.01
Coordinates of the center of gravity: (-0.18023; 0.36095; 0.29286)
Moment of inertia Ix is: 83.776 Da*(Å^2)
Moment of inertia Iz is: 170.861 Da*(Å^2)
This is Moment of inertia version 1.1
System date is Mon Feb 25 20:18:04 2019
Calculation for data from file /mnt/e/Pentane.xyz
The calculation with step of the directing vector is 0.05
-------------------------------------------------
|Coordinates of the center of gravity |
-------------------------------------------------
|x |y |z |
-------------------------------------------------
|3.13712 |0.78884 |-0.90687 |
-------------------------------------------------
-------------------------------------------------
|Moments of inertia, Da*A^2 |
-------------------------------------------------
|Ix |Iz |
-------------------------------------------------
|29.989 |269.277 |
-------------------------------------------------
-------------------------------------------------------
```

You can set the parameters of the program using the following startup keys:
Expand All @@ -38,32 +55,45 @@ You can set the parameters of the program using the following startup keys:

**-d** - Display coordinates of axis directing vectors with minimum and maximum inertia moments.

For example, the result of the calculation for the pentane molecule using the XYZ file from the *Examples* folder with the keys will look like this:

```
Calculation for data from file ./Pentane.xyz
The calculation with step of the directing vector is 0.01
Coordinates of the center of gravity: (3.13712; 0.78884; -0.90687)
Moment of inertia Ix is: 29.987 Da*(Å^2)
Moment of inertia Iz is: 269.277 Da*(Å^2)
```
**-i** - Display the initial information for the calculation.

And when you run a program with keys
For example, the result of the calculation for the pentane molecule using the XYZ file from the *Examples* folder with the keys **-a2** **-o4** **-d** will look like this:

```
$ ./moments_of_inertia.pl -a2 -o4 -d ./Pentane.xyz
```

The result will look like this:
$ cat ./Pentane.txt
This is Moment of inertia version 1.1
System date is Mon Feb 25 20:24:44 2019
Calculation for data from file /mnt/e/Pentane.xyz
```
Calculation for data from file ../Pentane.xyz
The calculation with step of the directing vector is 0.05
Coordinates of the center of gravity: (3.13712; 0.78884; -0.90687)
Moment of inertia Ix is: 29.9888 Da*(Å^2)
Moment of inertia Iz is: 269.2769 Da*(Å^2)
Coordinates of the directing vector a_x = {i, j, k} is: 0.55 0.25 -0.3
Coordinates of the directing vector a_z = {i, j, k} is: 0 -0.85 -0.7
-------------------------------------------------
|Coordinates of the center of gravity |
-------------------------------------------------
|x |y |z |
-------------------------------------------------
|3.13712 |0.78884 |-0.90687 |
-------------------------------------------------
-------------------------------------------------
|Moments of inertia, Da*A^2 |
-------------------------------------------------
|Ix |Iz |
-------------------------------------------------
|29.9888 |269.2769 |
-------------------------------------------------
-------------------------------------------------
|Coordinates of the directing vectors |
-------------------------------------------------
| |i |j |k |
-------------------------------------------------
|a_x |0.55 |0.25 |-0.3 |
-------------------------------------------------
|a_z |0 |-0.85 |-0.7 |
-------------------------------------------------
-------------------------------------------------------
```

*Note!*
Expand Down
83 changes: 62 additions & 21 deletions moments_of_inertia.pl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# -a[1-5] - accuracy of the calculation of the moments of inertia (default is -a3)
# -o[1-5] - number of significant figures in the output result
# -d - display the coordinates of the directing vectors
my $version = "0.1_git_2";
my $version = "1.1";
my ($accuracy, $significant_figures, $direct_vector_output);

foreach (@ARGV) {
Expand Down Expand Up @@ -107,8 +107,8 @@
}

# Opening a file and reading information
my $filename = "$ARGV[-1]";
open(DATA, "$filename") or die "Could not open file '$filename' $!";
my $filename = $ARGV[-1];
open(DATA, $filename) or die "Could not open file $filename $!";
chomp(my @xyz = <DATA>);

# The number of atoms in a molecule
Expand All @@ -118,9 +118,14 @@
shift @xyz;

# Displays preliminary information about the calculation
open OUTPUT, ">>", "${filename}.txt";
print OUTPUT "\n";
$filename =~ s/...$/txt/; # Replacing file name extension with .txt
open OUTPUT, ">>", ${filename};
print OUTPUT "This is Moment of inertia version $version\n";

my $time = localtime;
print OUTPUT "System date is $time\n";
print OUTPUT "Calculation for data from file $ARGV[-1]\n";
print OUTPUT "\n";
print OUTPUT "The calculation with step of the directing vector is $accuracy\n";

# Delete first and last whitespace
Expand Down Expand Up @@ -161,12 +166,15 @@
my $Y_c = $sum_Ym / $sum_m;
my $Z_c = $sum_Zm / $sum_m;

# Rounding the coordinates of the center of masses and their output
my $X_c_rounded = sprintf("%.5f", $X_c);
my $Y_c_rounded = sprintf("%.5f", $Y_c);
my $Z_c_rounded = sprintf("%.5f", $Z_c);

print OUTPUT "Coordinates of the center of gravity: ($X_c_rounded; $Y_c_rounded; $Z_c_rounded)\n";
my $small_space = "-" x 49;
print OUTPUT "\n";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-47s|\n", "Coordinates of the center of gravity";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-15s|%-15s|%-15s|\n", "x", "y", "z";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-15.5f|%-15.5f|%-15.5f|\n", $X_c, $Y_c, $Z_c;
print OUTPUT "$small_space\n";

# The search of the moments of inertia with relative to the various lines passing through the center of masses
# @I is array of inertia moments, and @XaYaZa is array of coordinates of the directing vectors of the lines
Expand Down Expand Up @@ -194,19 +202,46 @@

my $I_min = &min(@I);
my $I_max = &max(@I);
my $I_min_rounded = sprintf("%.${significant_figures}f", $I_min);
my $I_max_rounded = sprintf("%.${significant_figures}f", $I_max);

print OUTPUT "Moment of inertia Ix is: $I_min_rounded Da*(Å^2)\n";
print OUTPUT "Moment of inertia Iz is: $I_max_rounded Da*(Å^2)\n";
print OUTPUT "\n";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-47s|\n", "Moments of inertia, Da*A^2";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-23s|%-23s|\n", "Ix", "Iz";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-23.${significant_figures}f|%-23.${significant_figures}f|\n", $I_min, $I_max;
print OUTPUT "$small_space\n";

if ($direct_vector_output) {
my $XaYaZa_MIN = &return_XaYaZa_MIN($I_min);
my $XaYaZa_MAX = &return_XaYaZa_MAX($I_max);
print OUTPUT "Coordinates of the directing vector a_x = {i, j, k} is: $XaYaZa_MIN\n";
print OUTPUT "Coordinates of the directing vector a_z = {i, j, k} is: $XaYaZa_MAX\n";
my @XaYaZa_MIN = &return_XaYaZa_MIN($I_min);
my @XaYaZa_MAX = &return_XaYaZa_MAX($I_max);
print OUTPUT "\n";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-47s|\n", "Coordinates of the directing vectors";
print OUTPUT "$small_space\n";
printf OUTPUT "|%11s|%-11s|%-11s|%-11s|\n", "", "i", "j", "k";
print OUTPUT "$small_space\n";
printf OUTPUT "|%-11s|%-11s|%-11s|%-11s|\n", "a_x", $XaYaZa_MIN[0], $XaYaZa_MIN[1], $XaYaZa_MIN[2];
print OUTPUT "$small_space\n";
printf OUTPUT "|%-11s|%-11s|%-11s|%-11s|\n", "a_z", $XaYaZa_MAX[0], $XaYaZa_MAX[1], $XaYaZa_MAX[2];
print OUTPUT "$small_space\n";
}

# Displaying initial data
foreach (@ARGV) {
if ($_ eq "-i") {
my @initial_data = map $_ . "\n", @xyz;
print OUTPUT "\n";
print OUTPUT "Initial data:\n";
foreach (@initial_data) {printf OUTPUT "%-6s %8s %8s %8s\n", (split)[0], (split)[1], (split)[2], (split)[3]}
print OUTPUT "\n";
last;
}
}

my $space = "-" x 55;
print OUTPUT "$space\n";

close OUTPUT;

# ======================================================================
Expand Down Expand Up @@ -265,15 +300,21 @@ sub max {
sub return_XaYaZa_MIN {
my $count = 0;
foreach (@I) {
if ($_ =~ /$I_min/) {return $XaYaZa[$count]}
if ($_ =~ /$I_min/) {
my @coord_MIN = split /\s+/, $XaYaZa[$count];
return @coord_MIN;
}
$count++;
}
}

sub return_XaYaZa_MAX {
my $count = 0;
foreach (@I) {
if ($_ =~ /$I_max/) {return $XaYaZa[$count]}
if ($_ =~ /$I_max/) {
my @coord_MAX = split /\s+/, $XaYaZa[$count];
return @coord_MAX;
}
$count++;
}
}

0 comments on commit da00181

Please sign in to comment.