def importNomalized(pathName, exp):
    labelsList = list()
    ch_names = []
    create_ch_name = False
    # carregando pasta "large_train"
    path = gop('ls {}'.format(pathName)).split('\n')
    # 1ª dimensão dos dados contendo os sujeitos. Ex.: C_1, a_m, etc
    subjects = list()
    for types in path:
        if("co2c" in types):
            for i in range (0,10):
                labelsList.append([[0]]*61)
        else:
            for i in range (0,10):
                labelsList.append([[1]]*61)

        files = gop('ls {}/{}'.format(pathName, types)).split('\n')
        # 2ª dimensão dos dados contendo as sessões (trials)
        
        trials = list()
        for f in files:
            arquivo = open('{}/{}/{}'.format(pathName, types, f))
            text = arquivo.readlines()
            # 3ª dimensão dos dados contendo os canais (eletrodos)
            chs = list()
            # 4ª dimensão dos dados contendo os valores em milivolts
            values = list()
            for line in text:
                # ex: "# FP1 chan 0"
                t = search('(?P<ch_name>\w{1,3}) chan \d{1,2}', line)
                # ex: "0 FP1 0 -8.921"
                p = search('^\d{1,2}\ \w{1,3}\ \d{1,3}\ (?P<value>.+$)', line)
                if p:
                    values.append(float(p.group('value')))
                # mudou para outro eletrodo
                elif t:
                    if values:
                        chs.append(values)
                        values = list()
                    if not create_ch_name:
                        ch_names.append(t.group('ch_name').lower())
            create_ch_name = True
            chs.append(values)

            arquivo.seek(32*3)
            line =  arquivo.readline()
            arquivo.close()

            if exp in line:
                trials.append(chs)

        subjects.append(trials)
    data = np.array(subjects)
    
    return [filterData(data),np.asarray(labelsList)]
def calculate_boxsize(pdbfile, tmp_prefix=".tmp"):
    tmp_prefix=f"{tmpdir}/{tmp_prefix}"
    with open(f"{tmp_prefix}.in", "w") as fout:
        fout.write(tmp_leap.format(pdbfile=pdbfile, tmp_prefix=tmp_prefix))
    print(gop(f"tleap -f {tmp_prefix}.in | tee {tmp_prefix}.in.result"))
    center_str = gop(f"cat {tmp_prefix}.in.result | grep The\ center | cut -d: -f2 | sed s/,//g")
    center = [float(s) for s in center_str.split()]
    box_size_str = gop(f"tail -n 1 {tmp_prefix}.rst7 | cut -c -36")
    box_size = [float(s) for s in box_size_str.split()]
    box_size = max(box_size)

    return box_size
Esempio n. 3
0
def load_bases2(path_files):
    diretory = gop('ls {}'.format(folders[path_files])).split('\n')

    subA = {"S1_obj": [], "S2_nomatch": [], "S2_match": []}
    subC = {"S1_obj": [], "S2_nomatch": [], "S2_match": []}

    for types in diretory:
        files = gop('ls {}/{}'.format(folders[path_files], types)).split('\n')
        if 'Co2A' in types.title():
            get_all_datas(files, subA, path_files, types)
        else:
            get_all_datas(files, subC, path_files, types)

    return [subA, subC]
def gen_packmol_input(protein_pdb, cosolv_pdbs, box_pdb, inp, box_size, molar):
    # shorten path length to pdb file
    # too long path cannot be treated by packmol
    temp_protein_pdb = f"{tmpdir}/.temp_protein.pdb"
    print(gop(f"cp {protein_pdb} {temp_protein_pdb}"))

    temp_pdbs = [f"{tmpdir}/.temp_{i}.pdb" for i in range(len(cosolv_pdbs))]
    [gop(f"cp {src} {dst}") for src, dst in zip(cosolv_pdbs, temp_pdbs)]

    num = int(constants.N_A * molar * (box_size**3) * (10**-27))
    with open(inp, "w") as fout:
        fout.write(TEMPLATE_PACKMOL_HEADER.format(output=box_pdb, prot=temp_protein_pdb))
        fout.write("\n")
        for pdb in temp_pdbs:
            fout.write(TEMPLATE_PACKMOL_STRUCT.format(cosolv=pdb, num=num, size=box_size/2))
            fout.write("\n")
def run_tleap(tleap_path, inp):
    output = gop("%s -f %s" % (tleap_path, inp))
    print(output)
    final_charge_info = [s.strip() for s in output.split("\n")
                         if s.strip().startswith("Total unperturbed charge")][0]
    final_charge_value = float(final_charge_info.split()[-1])
    return final_charge_value
Esempio n. 6
0
def do_cpptraj(top,
               resi_st,
               resi_ed,
               traj,
               ref,
               ref_resi_st,
               ref_resi_ed,
               cid,
               prefix,
               n=100,
               d=1,
               traj_start=1,
               traj_stop="last",
               traj_offset=1,
               cpptraj_exe="cpptraj"):

    log = gop(f"""{cpptraj_exe} -p {top} << EOF
trajin {traj} {traj_start} {traj_stop} {traj_offset}
parm {ref}
reference {ref} parm {ref} [REF]

unwrap :{resi_st}-{resi_ed}@CA
center :{resi_st}-{resi_ed}@CA
fiximagedbonds
autoimage

rms ToREF ref [REF] :{resi_st}-{resi_ed}@CA :{ref_resi_st}-{ref_resi_ed}@CA out rmsd.dat


# "center" maybe changed AFTER grid generation. be careful...
# file name must not start with a number (i.e. 1L2S_A11_nV.dx)
# grid map_{prefix}_nV.dx  {n} {d} {n} {d} {n} {d} center :{resi_st}-{resi_ed}@CA :{cid}&(!@VIS)
# grid map_{prefix}_nVH.dx {n} {d} {n} {d} {n} {d} center :{resi_st}-{resi_ed}@CA :{cid}&(!@VIS)&(!@H*)
# grid map_{prefix}_V.dx   {n} {d} {n} {d} {n} {d} center :{resi_st}-{resi_ed}@CA :{cid}@VIS
# grid map_{prefix}_O.dx   {n} {d} {n} {d} {n} {d} center :{resi_st}-{resi_ed}@CA :{cid}@O*
grid map_{prefix}_nV.dx  {n} {d} {n} {d} {n} {d} :{cid}&(!@VIS)
grid map_{prefix}_nVH.dx {n} {d} {n} {d} {n} {d} :{cid}&(!@VIS)&(!@H*)
grid map_{prefix}_V.dx   {n} {d} {n} {d} {n} {d} :{cid}@VIS
grid map_{prefix}_O.dx   {n} {d} {n} {d} {n} {d} :{cid}@O*

trajout {prefix}_position_check.pdb start 1 stop 1 offset 1
trajout {prefix}_position_check2.pdb offset 100
go
exit
EOF""")
    print(log)
Esempio n. 7
0
def main():
    # arquivos
    arquivos = gop('ls data_10hz').split('\n')

    # Tempos selecionados a mão
    times = [[95, 96, 234, 367, 597, 786],
            [39, 46, 110, 130, 280, 363],
            [103, 114, 136, 154, 171, 185]]
    window = 3
    
    # Para cada arquivo
    for arqPos, arq in enumerate(arquivos):
        data, fileLimitTime = loadData(arq)
        print(data.shape)
        raw = prepareRaw(data)

        # acha os tempos do ritmo alpha
        for i in range(fileLimitTime - window):
            findAlphaTime(raw, i, window)

        # plota os tempos selecionados
        for i in times[arqPos]:
            plotWindowTime(raw, i, window)
Esempio n. 8
0
    def load_data_with_label(self):
        create_ch_name = False
        subjects = []
        labels = []

        # get all dirs inside folder
        folder = gop('ls {}'.format(self.folder_path)).split('\n')
        # for all dir insider folder
        for types in folder:
            if (not os.path.isdir('{}/{}'.format(self.folder_path, types))):
                continue
            label_search = search('^co2(?P<label>\w{1})', types)

            files = gop('ls {}/{}'.format(self.folder_path, types)).split('\n')
            # 2ª dimensão dos dados contendo as sessões (trials)
            trials = list()

            # for all file in files
            for f in files:
                if (label_search.group("label") == "a"):
                    labels.append(1)
                else:
                    labels.append(0)
                arquivo = open('{}/{}/{}'.format(self.folder_path, types, f))
                text = arquivo.readlines()
                # 3ª dimensão dos dados contendo os canais (eletrodos)
                chs = list()
                # 4ª dimensão dos dados contendo os valores em milivolts
                values = list()
                # for each line inside a file
                for line in text:
                    # ex: "# FP1 chan 0"
                    # look if this line is a new eletrodo info
                    t = search('(?P<ch_name>\w{1,3}) chan \d{1,2}', line)
                    # ex: "0 FP1 0 -8.921"
                    # or if is a data line
                    p = search('^\d{1,3}\ \w{1,3}\ \d{1,3}\ (?P<value>.+$)',
                               line)

                    # if has a eeg data
                    if p:
                        values.append(float(p.group('value')))
                    # mudou para outro eletrodo
                    elif t:
                        if values:
                            chs.append(values)
                            values = list()
                        if not create_ch_name:
                            self.ch_names.append(t.group('ch_name').lower())

                # end for line
                # append last channel
                chs.append(values)
                create_ch_name = True

                # append all channels to one trial
                trials.append(chs)
                arquivo.close()
            # append all trials to one subject
            subjects.append(trials)
            self.subjects = np.array(subjects)
            self.labels = np.array(labels)
def run_packmol(packmol_path, inp):
    print(gop("%s < %s" % (packmol_path, inp)))
def run_parmchk(mol2, frcmod, at):
    at_id = {"gaff": 1, "gaff2": 2}[at]
    print(gop(f"parmchk2 -i {mol2} -f mol2 -o {frcmod} -s {at_id}"))
    cosolv_box_size = ((constants.N_A * float(params["Cosolvent"]["molar"]))
                       * 1e-27)**(-1/3.0)  # /L -> /A^3 : 1e-27

    # 1. generate cosolvent box with packmol
    packmol_input = f"{tmpdir}/.temp_packmol.input"
    packmol_box_pdb = f"{tmpdir}/.temp_box.pdb"
    cfrcmods = [f"{tmpdir}/.temp_cosolvent_{cid}.frcmod" for cid in cids]
    gen_packmol_input(params["Protein"]["pdb"], cpdbs,
                      packmol_box_pdb,
                      packmol_input,
                      boxsize,
                      float(params["Cosolvent"]["molar"]))
    while True:
        run_packmol(args.packmol, packmol_input)  # -> output: packmol_box_pdb
        temp_box = f"{tmpdir}/.temp_packmol_box_2.pdb"
        gop("grep -v OXT {} > {}".format(packmol_box_pdb, temp_box))

        for mol2, frcmod in zip(cmols, cfrcmods):
            run_parmchk(mol2, frcmod, params["Cosolvent"]["atomtype"])


        # 2. amber tleap
        tleap_input = f"{tmpdir}/.temp_tleap.in"
        gen_tleap_input(expandpath(args.tleap_input), tleap_input,
                        cids, cmols,
                        cfrcmods,
                        temp_box,
                        boxsize,
                        args.output_prefix,
                        ssbonds,
                        params["Cosolvent"]["atomtype"])
    print('Downlod dos datasets concluído!')
else:
    print('Dataset já baixado!')

from subprocess import getoutput as gop
import glob

# único arquivo somente empacotado (tar)
# os.mkdir('dataset/eeg_full/')
# gop('tar -xvf dataset/eeg_full.tar -C dataset/eeg_full')
# os.remove('dataset/eeg_full.tar')

while glob.glob('dataset/**/*.gz', recursive=True):
    # quando o arquivo está empacotado (tar) e compactado (gz)
    for f in glob.iglob('dataset/**/*.tar.gz', recursive=True):
        gop('tar -zxvf {} -C {}'.format(f, f[:f.rindex('/')]))
        os.remove(f)
    # quando o arquivo está somente compactado (gz)
    for f in glob.iglob('dataset/**/*.gz', recursive=True):
        gop('gzip -d {}'.format(f))
print('Descompactações finalizadas!')

# organizando melhor as pastas
os.rename('dataset/smni_eeg_data', 'dataset/small')
# os.rename('dataset/eeg_full', 'dataset/full')
os.rename('dataset/SMNI_CMI_TRAIN/', 'dataset/large_train/')
os.rename('dataset/SMNI_CMI_TEST/', 'dataset/large_test/')
print(gop('ls -l dataset/'))

from re import search
import numpy as np