Example #1
0
 def __init__(self, directory='.'):
     self.directory = directory
     with cd(directory):
         try:
             self.meta = VASPMeta.from_file('vaspmeta.yaml')
         except FileNotFoundError as e:
             raise type(e)(str(e) +
                           ' in {}'.format(directory)).with_traceback(
                               sys.exc_info()[2])
         self.parse_vasprun()
     self.print_methods = {
         'title': self.print_title,
         'type': self.print_type,
         'status': self.print_status,
         'stoichiometry': self.print_stoichiometry,
         'potcar': self.print_potcar,
         'eatom': self.print_eatom,
         'energy': self.print_energy,
         'k-points': self.print_kpoints,
         'functional': self.print_functional,
         'encut': self.print_encut,
         'plus_u': self.print_plus_u,
         'ediffg': self.print_ediffg,
         'ibrion': self.print_ibrion,
         'converged': self.print_converged,
         'version': self.print_version,
         'md5': self.print_vasprun_md5,
         'directory': self.print_directory,
         'lreal': self.print_lreal,
         'vbm': self.print_vbm,
         'cbm': self.print_cbm
     }
Example #2
0
 def test_init_vaspmeta_with_invalid_type_raises_valueerror(self):
     title = 'title'
     description = 'description'
     status = 'finished'
     type = 'invalid type'
     with self.assertRaises(ValueError):
         VASPMeta(title, description, status, type=type)
Example #3
0
 def test_init_vaspmeta_with_file_tracking(self):
     title = 'title'
     description = 'description'
     status = 'finished'
     track = {'DOSCAR': 'doscar', 'CHGCAR': 'chgcar'}
     vaspmeta = VASPMeta(title, description, status, track=track)
     self.assertEqual(vaspmeta.track, track)
Example #4
0
 def test_init_vaspmeta_with_valid_type(self):
     title = 'title'
     description = 'description'
     status = 'finished'
     valid_types = ['single-point', 'neb']
     for t in valid_types:
         vaspmeta = VASPMeta(title, description, status, type=t)
         self.assertEqual(vaspmeta.type, t)
Example #5
0
 def test_init_vaspmeta(self):
     title = 'title'
     description = 'description'
     notes = 'notes'
     valid_status = ['to-run', 'incomplete', 'finished', 'dropped']
     for s in valid_status:
         vaspmeta = VASPMeta(title, description, status=s, notes=notes)
         self.assertEqual(vaspmeta.title, title)
         self.assertEqual(vaspmeta.description, description)
         self.assertEqual(vaspmeta.status, s)
         self.assertEqual(vaspmeta.notes, notes)
Example #6
0
    def test_from_file_with_type( self ):
        example_file = """\
title: title
description: description
status: finished
type: single-point\
"""
        with patch( 'vasppy.vaspmeta.VASPMeta' ) as mock_VASPMeta:
            with patch( 'builtins.open', mock_open( read_data=example_file ), create=True ) as m:
                vaspmeta = VASPMeta.from_file( example_file )
        mock_VASPMeta.assert_called_with( 'title', 'description', 'finished', notes=None, type='single-point' )
        self.assertEqual( vaspmeta, mock_VASPMeta.return_value )
Example #7
0
    def test_from_file( self ):
        example_file = """\
title: title
description: description
notes: notes
status: finished\
"""
        with patch( 'vasppy.vaspmeta.VASPMeta' ) as mock_VASPMeta:
            mock_VASPMeta.return_value = 'my VASP metadata'
            with patch( 'builtins.open', mock_open( read_data=example_file ), create=True ) as m:
                vaspmeta = VASPMeta.from_file( example_file )
        mock_VASPMeta.assert_called_with( 'title', 'description', 'finished', notes='notes', type=None )
        self.assertEqual( vaspmeta, mock_VASPMeta.return_value )
Example #8
0
def main():
    supported_flags = Summary.supported_flags
    to_print = [
        'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy',
        'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion',
        'converged', 'version', 'md5', 'directory'
    ]
    titles = None
    args = get_args()
    if args.list:
        for k, v, in supported_flags.items():
            print("{}: {}".format(k.ljust(15), v))
        sys.exit()
    if args.file:
        with open(args.file, 'r') as stream:
            settings = yaml.load(stream)
        if 'to_print' in settings:
            to_print = settings['to_print']
        if 'titles' in settings:
            titles = settings['titles']
    if args.print:
        not_supported = [p for p in args.print if p not in supported_flags]
        if not_supported:
            raise ValueError(not_supported)
        else:
            to_print = args.print
    if args.recursive:
        path = sorted(find_vasp_calculations())
    else:
        path = ['.']
    if args.check:
        for p in path:
            vaspmeta = Path('{}/vaspmeta.yaml'.format(p))
            if not vaspmeta.is_file():
                print('{} is missing vaspmeta.yaml'.format(p))
            vasprun = Path('{}/vasprun.xml'.format(p))
            if not vasprun.is_file():
                print('{} is missing vasprun.xml'.format(p))
    else:
        if titles:
            # Only parse directories with matching vasp_meta titles
            matching_path = []
            for p in path:
                vm = VASPMeta.from_file('{}/vaspmeta.yaml'.format(p))
                if vm.title in titles:
                    matching_path.append(p)
            path = matching_path
        for p in path:
            s = Summary(p)
            s.output(to_print=to_print)
Example #9
0
def main():
    supported_flags = Summary.supported_flags
    to_print=[ 'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy', 'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion', 'converged', 'version', 'md5', 'directory' ]
    titles = None
    args = get_args()
    if args.list:
        for k, v, in supported_flags.items():
            print( "{}: {}".format( k.ljust(15), v ) )
        sys.exit()
    if args.file:
        with open( args.file, 'r' ) as stream:
            settings = yaml.load( stream, Loader=yaml.SafeLoader ) 
        if 'to_print' in settings:
            to_print = settings['to_print']
        if 'titles' in settings:
            titles = settings['titles']
    if args.print:
        not_supported = [ p for p in args.print if p not in supported_flags ]
        if not_supported:
            raise ValueError( not_supported )
        else:
            to_print = args.print
    if args.recursive:
        path = sorted( find_vasp_calculations() )
    else:
        path = [ '.' ]
    if args.check:
        for p in path:
           vaspmeta = Path( '{}/vaspmeta.yaml'.format( p ) )
           if not vaspmeta.is_file(): 
               print( '{} is missing vaspmeta.yaml'.format( p ) ) 
           vasprun  = Path( '{}/vasprun.xml'.format( p ) )
           if not vasprun.is_file():
               print( '{} is missing vasprun.xml'.format( p ) ) 
    else:
        if titles:
            # Only parse directories with matching vasp_meta titles
            matching_path = []
            for p in path:
                vm = VASPMeta.from_file( '{}/vaspmeta.yaml'.format(p) )
                if vm.title in titles:
                    matching_path.append( p )
            path = matching_path
        for p in path:
            s = Summary( p )
            s.output( to_print=to_print )
Example #10
0
    def test_from_file_with_no_notes_entry(self):
        example_file = """\
title: title
description: description
status: finished\
"""
        with patch('vasppy.vaspmeta.VASPMeta') as mock_VASPMeta:
            mock_VASPMeta.return_value = 'my VASP metadata'
            with patch('builtins.open',
                       mock_open(read_data=example_file),
                       create=True) as m:
                vaspmeta = VASPMeta.from_file(example_file)
        mock_VASPMeta.assert_called_with('title',
                                         'description',
                                         'finished',
                                         notes=None,
                                         type=None)
        self.assertEqual(vaspmeta, mock_VASPMeta.return_value)
Example #11
0
 def __init__(self, directory='.'):
     self.directory = directory
     with cd(directory):
         try:
             self.meta = VASPMeta.from_file('vaspmeta.yaml')
         except FileNotFoundError as e:
             raise FileNotFoundError(
                 f'vaspmeta.yaml not found in {directory}')
         self.parse_vasprun()
     self.print_methods = {
         'title': self.print_title,
         'description': self.print_description,
         'notes': self.print_notes,
         'type': self.print_type,
         'status': self.print_status,
         'stoichiometry': self.print_stoichiometry,
         'potcar': self.print_potcar,
         'eatom': self.print_eatom,
         'energy': self.print_energy,
         'k-points': self.print_kpoints,
         'functional': self.print_functional,
         'encut': self.print_encut,
         'plus_u': self.print_plus_u,
         'ediffg': self.print_ediffg,
         'ibrion': self.print_ibrion,
         'converged': self.print_converged,
         'version': self.print_version,
         'md5': self.print_vasprun_md5,
         'directory': self.print_directory,
         'lreal': self.print_lreal,
         'vbm': self.print_vbm,
         'cbm': self.print_cbm,
         'track': self.print_file_tracking,
         'nelect': self.print_nelect
     }
     if not set(self.print_methods.keys()) == set(self.supported_flags):
         print(set(self.print_methods.keys()))
         print('--------------')
         print(set(self.supported_flags.keys()))
         raise (ValueError)
Example #12
0
 def __init__( self, directory='.' ):
     self.directory = directory
     with cd( directory ):
         try:
             self.meta = VASPMeta.from_file( 'vaspmeta.yaml' )
         except FileNotFoundError as e:
             raise type(e)( str(e) + ' in {}'.format( directory )).with_traceback( sys.exc_info()[2] )
         self.parse_vasprun()
     self.print_methods = { 'title': self.print_title,
                            'description': self.print_description,
                            'notes': self.print_notes,
                            'type': self.print_type,
                            'status': self.print_status,
                            'stoichiometry': self.print_stoichiometry,
                            'potcar': self.print_potcar,
                            'eatom': self.print_eatom,
                            'energy': self.print_energy,
                            'k-points': self.print_kpoints,
                            'functional': self.print_functional,
                            'encut': self.print_encut,
                            'plus_u': self.print_plus_u,
                            'ediffg': self.print_ediffg,
                            'ibrion': self.print_ibrion,
                            'converged': self.print_converged,
                            'version': self.print_version,
                            'md5': self.print_vasprun_md5,
                            'directory': self.print_directory,
                            'lreal': self.print_lreal,
                            'vbm': self.print_vbm,
                            'cbm': self.print_cbm,
                            'track': self.print_file_tracking, 
                            'nelect': self.print_nelect }
     if not set( self.print_methods.keys() ) == set( self.supported_flags ):
         print( set( self.print_methods.keys() ) )
         print( '--------------' )
         print( set( self.supported_flags.keys() ) )
         raise( ValueError )
Example #13
0
def main():
    supported_flags = Summary.supported_flags
    to_print = [
        'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy',
        'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion',
        'converged', 'version', 'md5', 'directory'
    ]
    titles = None
    args = get_args()
    if args.list:
        for k, v, in supported_flags.items():
            print("{}: {}".format(k.ljust(15), v))
        sys.exit()
    if args.file:
        with open(args.file, 'r') as stream:
            settings = yaml.load(stream, Loader=yaml.SafeLoader)
        if 'to_print' in settings:
            to_print = settings['to_print']
        if 'titles' in settings:
            titles = settings['titles']
    if args.print:
        not_supported = [p for p in args.print if p not in supported_flags]
        if not_supported:
            raise ValueError(not_supported)
        else:
            to_print = args.print
    if args.recursive:
        path = sorted(find_vasp_calculations())
    else:
        path = ['.']
    if args.check:
        for p in path:
            vaspmeta = Path('{}/vaspmeta.yaml'.format(p))
            if not vaspmeta.is_file():
                print('{} is missing vaspmeta.yaml'.format(p))
            vasprun = Path('{}/vasprun.xml'.format(p))
            if not vasprun.is_file():
                print('{} is missing vasprun.xml'.format(p))
    else:
        if titles:
            # Only parse directories with matching vasp_meta titles
            matching_path = []
            for p in path:
                vm = VASPMeta.from_file('{}/vaspmeta.yaml'.format(p))
                if vm.title in titles:
                    matching_path.append(p)
            path = matching_path
        if args.maxjobs:
            n = len(path)
            with Pool(args.maxjobs) as p:
                if args.progress_bar:
                    summaries = list(
                        tqdm.tqdm(p.imap(get_summary, path), total=len(path)))
                else:
                    summaries = p.map(get_summary, path)
        else:
            if args.progress_bar:
                path_iterator = tqdm.tqdm(path, unit='vasprun')
            else:
                path_iterator = path
            summaries = [get_summary(p) for p in path_iterator]
        if args.progress_bar:
            iterable = tqdm.tqdm(summaries, unit='records')
        else:
            iterable = summaries
        for s in iterable:
            s.output(to_print=to_print)
Example #14
0
 def test_init_vaspmeta_with_no_file_tracking(self):
     title = 'title'
     description = 'description'
     status = 'finished'
     vaspmeta = VASPMeta(title, description, status)
     self.assertEqual(vaspmeta.track, None)
Example #15
0
 def test_init_vaspmeta_with_invalid_status_raises_valueerror(self):
     title = 'title'
     description = 'description'
     invalid_status = 'foo'
     with self.assertRaises(ValueError):
         VASPMeta(title, description, status=invalid_status)
Example #16
0
    if args.print:
        not_supported = [p for p in args.print if p not in supported_flags]
        if not_supported:
            raise ValueError(not_supported)
        else:
            to_print = args.print
    if args.recursive:
        path = sorted(find_vasp_calculations())
    else:
        path = ['.']
    if args.check:
        for p in path:
            vaspmeta = Path('{}/vaspmeta.yaml'.format(p))
            if not vaspmeta.is_file():
                print('{} is missing vaspmeta.yaml'.format(p))
            vasprun = Path('{}/vasprun.xml'.format(p))
            if not vasprun.is_file():
                print('{} is missing vasprun.xml'.format(p))
    else:
        if titles:
            # Only parse directories with matching vasp_meta titles
            matching_path = []
            for p in path:
                vm = VASPMeta.from_file('{}/vaspmeta.yaml'.format(p))
                if vm.title in titles:
                    matching_path.append(p)
            path = matching_path
        for p in path:
            s = Summary(p)
            s.output(to_print=to_print)