Skip to content

Commit

Permalink
updated all cosymlib scripts.
Browse files Browse the repository at this point in the history
Now they have common header and footer
All have a new argparse argument (-v or --version) which returns the actual cosymlib version
Fixed the yaml command input reading to return an error message when a key from the input is not an argument of the script
  • Loading branch information
efrembernuz committed Dec 9, 2020
1 parent 038ebea commit 11d3d14
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 49 deletions.
39 changes: 27 additions & 12 deletions scripts/cosym
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/usr/bin/env python
import argparse
import numpy as np
import yaml
import sys
from cosymlib import Cosymlib, __version__
from cosymlib import file_io
from cosymlib.molecule.geometry import Geometry
from cosymlib import Cosymlib
from cosymlib.file_io.tools import add_extra_keywords, print_header, print_footer, print_input_info
from cosymlib.shape import tools
from cosymlib.molecule.geometry import Geometry
import argparse
import sys
import yaml
import os
import numpy as np


parser = argparse.ArgumentParser(description='Cosym')
parser.add_argument(type=str, dest='input_file', help='input file name(+extension)')
parser.add_argument(type=str, dest='input_file', nargs='?', default=None, help='input file name(+extension)')
parser.add_argument(type=str, dest="yaml_input", nargs='?', default=None,
help='Perform the calculations with the command file')
parser.add_argument('-o', '--output_name', dest='output_name', default=None, help='save in file name')
parser.add_argument('-info', action='store_true', default=False, help='return information about the input geometries')
parser.add_argument('--info', action='store_true', default=False, help='return information about the input geometries')
parser.add_argument('-v', '--version', dest='version', action='store_true', default=False,
help='print information about the input structures')

parser.add_argument('-c', '--central_atom', action='store', dest='central_atom',
type=int, default=0, help='position of the central atom if exist')
Expand Down Expand Up @@ -112,7 +115,7 @@ parser.add_argument('-mo_diagram', dest="mo_diagram", action='store_true', defau


args = parser.parse_args(sys.argv[1:])
print('Starting...')
# print('Starting...')

if args.yaml_input:
with open(args.yaml_input, 'r') as stream:
Expand All @@ -124,7 +127,17 @@ if args.yaml_input:
else:
raise KeyError("Key %s is not valid" % key)

if args.input_file is not None:
if args.version:
print('Cosymlib version = {}'.format(__version__))
exit()

common_output = open(args.output_name, 'w') if args.output_name is not None else sys.stdout
print_header(common_output)

if args.input_file is None:
print('No input file selected!'.format(args.input_file))
exit()
else:
structures = file_io.read_generic_structure_file(args.input_file, read_multiple=True)
symobj = Cosymlib(structures)

Expand Down Expand Up @@ -155,7 +168,8 @@ if args.shp_references:
# file_io.write_file_xyz(test_structure, output_name='ML{}_ref'.format(n_atoms))

if args.info:
file_io.write_input_info(structures, output_name=args.output_name)
print_input_info(structures, output=common_output)
exit()

# Shape's commands
if args.shp_labels:
Expand Down Expand Up @@ -230,4 +244,5 @@ if args.pointgroup:
for idm, pg in enumerate(symobj.get_point_group()):
print('The point group of molecule{} is: {}'.format(idm, pg))

print('\nEnd of cosym calculation')
# print('\nEnd of cosym calculation')
print_footer(common_output)
49 changes: 36 additions & 13 deletions scripts/esym
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env python
from cosymlib.file_io.tools import add_extra_keywords, extract_geometries, print_header, print_footer, print_input_info
from cosymlib import Cosymlib, __version__
from cosymlib.file_io.tools import add_extra_keywords, print_header, print_footer, print_input_info
from cosymlib.file_io import read_generic_structure_file
from cosymlib.symmetry.tools import print_symmetry_labels
from cosymlib import Cosymlib
import argparse
import sys
import yaml


parser = argparse.ArgumentParser(description='esym')

# positional arguments
parser.add_argument(type=str,
dest='input_file',
nargs='?', default=None,
help='input file with structures')
parser.add_argument(type=str,
dest="yaml_input",
Expand All @@ -23,17 +25,28 @@ parser.add_argument('-m', '--measure',
metavar='SG',
default=False,
help='compute the SG symmetry measure of the input structures')
parser.add_argument('-l', '--labels',
dest='labels',
action='store_true',
default=False,
help='print the symmetry labels (SG) for the groups that can be used')
parser.add_argument('-o', '--output',
dest='output_name',
metavar='filename',
default=None,
help='store output into a file')

# Extra options
parser.add_argument('-l', '--labels',
dest='labels',
action='store_true',
default=False,
help='print the symmetry labels (SG) for the groups that can be used')
parser.add_argument('--info',
action='store_true',
default=False,
help='print information about the input structures')
parser.add_argument('-v', '--version',
dest='version',
action='store_true',
default=False,
help='print information about the input structures')

# addtional print
parser.add_argument('--trans_matrices',
dest='trans_matrices',
Expand All @@ -53,11 +66,6 @@ parser.add_argument('--irrep',
action='store_true',
help='print the irreducible representations')

parser.add_argument('--info',
action='store_true',
default=False,
help='print information about the input structures')

# Modifiers
parser.add_argument('--center',
dest='center',
Expand All @@ -84,11 +92,26 @@ parser.add_argument('--axis2',
args = parser.parse_args()

if args.yaml_input:
add_extra_keywords(args, args.yaml_input)
with open(args.yaml_input, 'r') as stream:
input_parameters = yaml.load(stream, Loader=yaml.FullLoader)

for key, value in input_parameters.items():
if key.lower() in args:
setattr(args, key.lower(), value)
else:
raise KeyError("Key %s is not valid" % key)

if args.version:
print('Cosymlib version = {}'.format(__version__))
exit()

common_output = open(args.output_name, 'w') if args.output_name is not None else sys.stdout
print_header(common_output)

if args.input_file is None:
print('No input file selected!'.format(args.input_file))
exit()

structures = read_generic_structure_file(args.input_file, read_multiple=True)
structure_set = Cosymlib(structures)

Expand Down
40 changes: 32 additions & 8 deletions scripts/gsym
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env python
from cosymlib.file_io.tools import add_extra_keywords, extract_geometries, print_header, print_footer, print_input_info
from cosymlib import Cosymlib, __version__
from cosymlib.file_io.tools import add_extra_keywords, print_header, print_footer, print_input_info
from cosymlib.file_io import read_generic_structure_file, get_connectivity_from_file
from cosymlib.symmetry.tools import print_symmetry_labels
from cosymlib import Cosymlib
import argparse
import sys
import yaml


parser = argparse.ArgumentParser(description='tsym')

# positional arguments
parser.add_argument(type=str,
dest='input_file',
nargs='?', default=None,
help='input file with structures')
parser.add_argument(type=str,
dest="yaml_input",
Expand All @@ -28,11 +30,6 @@ parser.add_argument('-s', '--structure',
action='store_true',
default=False,
help='returns the nearest SG-symmetric structure to the reference one')
parser.add_argument('-l', '--labels',
dest='labels',
action='store_true',
default=False,
help='prints the symmetry labels (SG) for the groups that can be used')
parser.add_argument('-o', '--output',
dest='output_name',
metavar='filename',
Expand All @@ -45,10 +42,22 @@ parser.add_argument('-c', '--central_atom',
type=int,
default=0,
help='central atom is in position N in the input structure')

# Extra options
parser.add_argument('-l', '--labels',
dest='labels',
action='store_true',
default=False,
help='prints the symmetry labels (SG) for the groups that can be used')
parser.add_argument('--info',
action='store_true',
default=False,
help='print information about the input structures')
parser.add_argument('-v', '--version',
dest='version',
action='store_true',
default=False,
help='print information about the input structures')

# Modifiers
parser.add_argument('--ignore_connectivity',
Expand Down Expand Up @@ -84,11 +93,26 @@ parser.add_argument('--center',
args = parser.parse_args()

if args.yaml_input:
add_extra_keywords(args, args.yaml_input)
with open(args.yaml_input, 'r') as stream:
input_parameters = yaml.load(stream, Loader=yaml.FullLoader)

for key, value in input_parameters.items():
if key.lower() in args:
setattr(args, key.lower(), value)
else:
raise KeyError("Key %s is not valid" % key)

if args.version:
print('Cosymlib version = {}'.format(__version__))
exit()

common_output = open(args.output_name, 'w') if args.output_name is not None else sys.stdout
print_header(common_output)

if args.input_file is None:
print('No input file selected!'.format(args.input_file))
exit()

if args.connectivity_file:
connectivity = get_connectivity_from_file(args.connectivity_file)
else:
Expand Down
34 changes: 28 additions & 6 deletions scripts/shape
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env python
from cosymlib import Cosymlib, __version__
from cosymlib import file_io
from cosymlib.shape import tools
from cosymlib.file_io.tools import add_extra_keywords, print_header, print_footer, print_input_info
from cosymlib.file_io import read_generic_structure_file
from cosymlib import Cosymlib
from cosymlib.shape import tools
import argparse
import sys
import yaml


# positional arguments
parser = argparse.ArgumentParser(description='Shape')
parser = argparse.ArgumentParser(description='Shape', allow_abbrev=False)
parser.add_argument(type=str,
dest='input_file',
nargs='?',
default=None,
help='input file with structures')
parser.add_argument(type=str,
dest="yaml_input",
Expand Down Expand Up @@ -61,6 +63,11 @@ parser.add_argument('--info',
action='store_true',
default=False,
help='print information about the input structures')
parser.add_argument('-v', '--version',
dest='version',
action='store_true',
default=False,
help='print information about the input structures')

# Modifiers
parser.add_argument('--fix_permutation',
Expand All @@ -72,12 +79,27 @@ parser.add_argument('--fix_permutation',
args = parser.parse_args()

if args.yaml_input:
add_extra_keywords(args, args.yaml_input)
with open(args.yaml_input, 'r') as stream:
input_parameters = yaml.load(stream, Loader=yaml.FullLoader)

for key, value in input_parameters.items():
if key.lower() in args:
setattr(args, key.lower(), value)
else:
raise KeyError("Key %s is not valid" % key)

if args.version:
print('Cosymlib version = {}'.format(__version__))
exit()

common_output = open(args.output_name, 'w') if args.output_name is not None else sys.stdout
print_header(common_output)

structures = read_generic_structure_file(args.input_file, read_multiple=True)
if args.input_file is None:
print('No input file selected!'.format(args.input_file))
exit()

structures = file_io.read_generic_structure_file(args.input_file, read_multiple=True)
structure_set = Cosymlib(structures)

n_atoms = structure_set.get_n_atoms()
Expand Down

0 comments on commit 11d3d14

Please sign in to comment.