import sys
import os
import pickle
from os.path import exists

#drawfig_venn: unique([strs_all[i] for i in range(0,len(inperouts_vec)) if inperouts_vec[i][0] >= 1 and inperouts_vec[i][1] >= 1 and inperouts_vec[i][2] >= 1 and inperouts_vec[i][3] >= 1 and NoutputInsides_vec[i][0] >= 32 and NoutputInsides_vec[i][1] >= 32 and NoutputInsides_vec[i][2] >= 32 and NoutputInsides_vec[i][3] >= 32 ])[::-1] gives this:
goodOnes = ['python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 30.0 30.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 30.0 30.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 25.0 25.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 25.0 25.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 20.0 20.0 1000 0.0 0.9 10.0 10.0 10.0 250.0 ',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 15.0 15.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 15.0 15.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.9 10.0 10.0 10.0 250.0 ',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 30.0 30.0 1000 0.0 0.9 10.0 10.0 10.0 250.0 ',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 10.0 10.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 125 105 17.5 40.0 140.0 5.827500000000001 13.32 46.620000000000005 25.0 25.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 125 105 17.5 40.0 140.0 5.827500000000001 13.32 46.620000000000005 10.0 10.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 125 105 17.5 40.0 100.0 5.827500000000001 13.32 33.300000000000004 25.0 25.0 1000 0.0 0.9 10.0 10.0 10.0 200.0',
            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 125 105 17.5 40.0 100.0 5.827500000000001 13.32 33.300000000000004 10.0 10.0 1000 0.0 0.9 10.0 10.0 10.0 200.0'] 
#goodOnes = ['python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 30.0 30.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 25.0 25.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 25.0 25.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 25.0 25.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 20.0 20.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 15.0 15.0 1000 0.0 0.95 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 150 130 17.5 30.0 80.0 5.827500000000001 9.99 26.64 15.0 15.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 35.0 35.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 10.0 10.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 140 120 17.5 30.0 80.0 5.827500000000001 9.99 26.64 10.0 10.0 1000 0.0 0.9 10.0 10.0 10.0 250.0',
#            'python3 sim_mmns_2pm_sep_noISDIDD_savespikesonly.py 40 0.3 125 105 17.5 40.0 100.0 5.827500000000001 13.32 33.300000000000004 25.0 25.0 1000 0.0 0.9 10.0 10.0 10.0 200.0']
myseed = 1
if len(sys.argv) > 1:
  myseed = int(sys.argv[1])

def mystr(x):
  y = '{:.3f}'.format(x)
  while y.find('.') > -1 and y[-1] == '0':
    y = y[0:-1]
  return y
myseedAdd = '' if myseed == 1 else '_seed'+str(myseed)
  
areas = ['ACC','PFC','CTRL']
coeffs = [1.1916,1.0717,1.0] #From interpolate_fIcurve_membranetimeconstant_cortical.py
for iarea in [0,1,2]:
  area = areas[iarea]
  if len(sys.argv) > 2 and sys.argv[2] != area:
    continue
  
  for imodel in range(0,len(goodOnes)):
    attrs = goodOnes[imodel].split(' ')
    these_attrs = attrs[:]
    if len(sys.argv) > 3 and int(sys.argv[3]) != imodel:
      continue

    if iarea < 2:
      mychange = [[[17,18,19],mystr(10.0*coeffs[iarea])],[[20],mystr(float(these_attrs[20])*coeffs[iarea])]]

      for ichange in range(0,len(mychange)):
        if type(mychange[ichange][0]) is list:
          for imany in range(0,len(mychange[ichange][0])):
            these_attrs[mychange[ichange][0][imany]] = mychange[ichange][1]
        else:
          these_attrs[mychange[ichange][0]] = mychange[ichange][1]
    this_str = ' '.join(these_attrs)

    if not exists('MMNs_2pm_sep_noISDIDD_Nperpop'+these_attrs[2]+'_paramSD'+these_attrs[3]+'_stimA'+these_attrs[4]+'_'+these_attrs[5]+'_gAMPA'+these_attrs[6]+'_'+these_attrs[7]+'_'+these_attrs[8]+'_gNMDA'+these_attrs[9]+'_'+these_attrs[10]+'_'+these_attrs[11]+'_gGABA'+these_attrs[12]+'_'+these_attrs[13]+'_dep'+these_attrs[14]+'_'+these_attrs[15]+'_'+these_attrs[16]+'_tau'+these_attrs[17]+'_'+these_attrs[18]+'_'+these_attrs[19]+'_'+these_attrs[20]+myseedAdd+'.mat') and not exists('MMNs_2pm_sep_noISDIDD_model'+str(imodel)+'_'+area+'pop_AUCbased_seed'+str(myseed)+'.mat'):
      print(this_str+' '+str(myseed))
      os.system(this_str+' '+str(myseed))
    else:
      print('MMNs_2pm_sep_noISDIDD_Nperpop'+these_attrs[2]+'_paramSD'+these_attrs[3]+'_stimA'+these_attrs[4]+'_'+these_attrs[5]+'_gAMPA'+these_attrs[6]+'_'+these_attrs[7]+'_'+these_attrs[8]+'_gNMDA'+these_attrs[9]+'_'+these_attrs[10]+'_'+these_attrs[11]+'_gGABA'+these_attrs[12]+'_'+these_attrs[13]+'_dep'+these_attrs[14]+'_'+these_attrs[15]+'_'+these_attrs[16]+'_tau'+these_attrs[17]+'_'+these_attrs[18]+'_'+these_attrs[19]+'_'+these_attrs[20]+myseedAdd+'.mat MMNs_2pm_sep_noISDIDD_model'+str(imodel)+'_'+area+'pop_AUCbased_seed'+str(myseed)+'.mat exists')
    print('mv MMNs_2pm_sep_noISDIDD_Nperpop'+these_attrs[2]+'_paramSD'+these_attrs[3]+'_stimA'+these_attrs[4]+'_'+these_attrs[5]+'_gAMPA'+these_attrs[6]+'_'+these_attrs[7]+'_'+these_attrs[8]+'_gNMDA'+these_attrs[9]+'_'+these_attrs[10]+'_'+these_attrs[11]+'_gGABA'+these_attrs[12]+'_'+these_attrs[13]+'_dep'+these_attrs[14]+'_'+these_attrs[15]+'_'+these_attrs[16]+'_tau'+these_attrs[17]+'_'+these_attrs[18]+'_'+these_attrs[19]+'_'+these_attrs[20]+myseedAdd+'.mat MMNs_2pm_sep_noISDIDD_model'+str(imodel)+'_'+area+'pop_AUCbased_seed'+str(myseed)+'.mat')
    os.system('mv MMNs_2pm_sep_noISDIDD_Nperpop'+these_attrs[2]+'_paramSD'+these_attrs[3]+'_stimA'+these_attrs[4]+'_'+these_attrs[5]+'_gAMPA'+these_attrs[6]+'_'+these_attrs[7]+'_'+these_attrs[8]+'_gNMDA'+these_attrs[9]+'_'+these_attrs[10]+'_'+these_attrs[11]+'_gGABA'+these_attrs[12]+'_'+these_attrs[13]+'_dep'+these_attrs[14]+'_'+these_attrs[15]+'_'+these_attrs[16]+'_tau'+these_attrs[17]+'_'+these_attrs[18]+'_'+these_attrs[19]+'_'+these_attrs[20]+myseedAdd+'.mat MMNs_2pm_sep_noISDIDD_model'+str(imodel)+'_'+area+'pop_AUCbased_seed'+str(myseed)+'.mat')