<commit_before>from collections import OrderedDict
from math import sqrt

name = 'PWScf Input'
extension = 'pwi'
argument = '-pwi'

def parser(controller,data):
    """ Parse PWScf input files

    Namelists will be parsed and saved in PW parameter set
    Supported Cards:
    - ATOMIC_SPECIES
    - ATOMIC_POSITIONS
    - K_POINTS
    - CELL_PARAMETERS
    Not supported:
    - CONSTRAINTS
    - OCCUPATIONS
    - ATOMIC_FORCES (PWSCFv5)
    """
    controller.newMol()
    tmol = controller.getMol(-1)
    controller.newPw()
    tparam = controller.getPw(-1)
    tcoord = []
    tvec = [[0,0,0],[0,0,0],[0,0,0]]
    #parse data and create tparam
    while data:
        header = data.pop(0).strip().split()
        # ignore empty lines
        if not header:
            pass
        # parse namelists
        elif header[0][0] == '&':
            tnl = OrderedDict()
            # parse entries
            line = data.pop(0).strip().split(',')
            while line[0] != '/':
                for j in range(len(line)):
                    if line[j]:
                        tnl[line[j].split('=')[0].strip()]=line[j].split('=')[1].strip()
                line = data.pop(0).strip().split(',')
            tparam[header[0].lower()]=tnl
        # parse card
        elif header[0][0].isupper():
            #ATOMIC_SPECIES:
            #Name   Weight  PP-file
            if header[0] == 'ATOMIC_SPECIES':
                for i in range(int(tparam['&system']['ntyp'])):
                    line = data.pop(0).strip().split()
                    tmol.pse[line[0]]['m'] = float(line[1])
                    tmol.pse[line[0]]['PPfile'] = line[2]
            #ATOMIC_POSITIONS fmt
            #Name   x   y   z
            elif header[0] == 'ATOMIC_POSITIONS':
                fmt = header[1].strip('()')
                for i in range(int(tparam['&system']['nat'])):
                    #support empty lines
                    temp = data.pop(0).strip().split()
                    while not temp:
                            temp = data.pop(0).strip().split()
                    tcoord.append(temp)
            #K_POINTS fmt
            elif header[0] == 'K_POINTS':
                #Gamma point only
                if header[1] == 'gamma':
                    tmol.set_kpoints('active','gamma')
                #Monkhorst Pack Grid:
                #x y z offset
                elif header[1] == 'automatic':
                    line = data.pop(0).strip().split()
                    tmol.set_kpoints('automatic',line)
                    tmol.set_kpoints('active','automatic')
                #else:
                #number of kpoints<commit_msg>fix: optional arguments for PW-Input cards<commit_after>from collections import OrderedDict
from math import sqrt

name = 'PWScf Input'
extension = 'pwi'
argument = '-pwi'

def parser(controller,data):
    """ Parse PWScf input files

    Namelists will be parsed and saved in PW parameter set
    Supported Cards:
    - ATOMIC_SPECIES
    - ATOMIC_POSITIONS
    - K_POINTS
    - CELL_PARAMETERS
    Not supported:
    - CONSTRAINTS
    - OCCUPATIONS
    - ATOMIC_FORCES (PWSCFv5)
    """
    controller.newMol()
    tmol = controller.getMol(-1)
    controller.newPw()
    tparam = controller.getPw(-1)
    tcoord = []
    tvec = [[0,0,0],[0,0,0],[0,0,0]]
    #parse data and create tparam
    while data:
        header = data.pop(0).strip().split()
        # ignore empty lines
        if not header:
            pass
        # parse namelists
        elif header[0][0] == '&':
            tnl = OrderedDict()
            # parse entries
            line = data.pop(0).strip().split(',')
            while line[0] != '/':
                for j in range(len(line)):
                    if line[j]:
                        tnl[line[j].split('=')[0].strip()]=line[j].split('=')[1].strip()
                line = data.pop(0).strip().split(',')
            tparam[header[0].lower()]=tnl
        # parse card
        elif header[0][0].isupper():
            #ATOMIC_SPECIES:
            #Name   Weight  PP-file
            if header[0] == 'ATOMIC_SPECIES':
                for i in range(int(tparam['&system']['ntyp'])):
                    line = data.pop(0).strip().split()
                    tmol.pse[line[0]]['m'] = float(line[1])
                    tmol.pse[line[0]]['PPfile'] = line[2]
            #ATOMIC_POSITIONS fmt
            #Name   x   y   z
            elif header[0] == 'ATOMIC_POSITIONS':
                fmt = header[1].strip('{()}')
                for i in range(int(tparam['&system']['nat'])):
                    #support empty lines
                    temp = data.pop(0).strip().split()
                    while not temp:
                            temp = data.pop(0).strip().split()
                    tcoord.append(temp)
            #K_POINTS fmt
            elif header[0] == 'K_POINTS':
                #Gamma point only
                if header[1].strip('{()}') == 'gamma':
                    tmol.set_kpoints('active','gamma')
                #Monkhorst Pack Grid:
                #x y z offset
                elif header[1].strip('{()}') == 'automatic':
                    line = data.pop(0).strip().split()
                    tmol.set_kpoints('automatic',line)
                    tmol.set_kpoints('active','automatic')
                #else:
                #number of kpoints
{'fraction_non_alphanumeric': 0.14075591137590765, 'fraction_numerical': 0.013777695028858686, 'mean_word_length': 1.5303815355628827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '202174', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1614, 'n_words': 338}