Skip to content

Commit

Permalink
Merge pull request #31 from hernanchavezthielemann/opls_include_side
Browse files Browse the repository at this point in the history
Opls include side
  • Loading branch information
hernanchavezthielemann authored Jul 5, 2020
2 parents c24d804 + eb811c1 commit f9189fb
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
28 changes: 26 additions & 2 deletions lib/handling/gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ def extract_gromacs_data( _data_files_, _autoload_):

_aux_here_ = get_topitp_line( filename_bon, startstrings[ bi])
data_container[ s_str_], ok_flag, _data_define_ = _aux_here_


################################################################################### flag
# Make a function like dihedral integrity check
if bi == 2:
for di in range( len(data_container[ s_str_])):
# isnot_num return true if is string
dih_pt_line = data_container[ s_str_][di]
if not isnot_num( dih_pt_line[2]):
pop_wrg_1( 'Dihedral potential problem found!!\nAdopting'
+ ' X-A1-A2-X configuration for: '
+ ' {}-{}'.format( *dih_pt_line[:2]) )
new_row = ['X'] + dih_pt_line[:2] + ['X'] + dih_pt_line[2:]
data_container[ s_str_][di] = new_row

elif not isnot_num( dih_pt_line[3]):
exit('Error 0031 undefined dihedral')

data_container['define'][s_str_[:-5]] = _data_define_
#debugger_file(s_str_, data_container[s_str_])

Expand Down Expand Up @@ -301,11 +319,12 @@ def extract_gromacs_data( _data_files_, _autoload_):
improp_x_mol = len( sidemol['data'][sb]['impropers'])

sm_quantity = sidemol['num'][sb]
#print(sm_quantity, bonds_x_mol,sm_quantity * bonds_x_mol)
side_bonds_n += sm_quantity * bonds_x_mol
side_angles_n += sm_quantity * angles_x_mol
side_dihed_n += sm_quantity * dihedr_x_mol
side_improp_n += sm_quantity * improp_x_mol

n_bondsnew = n_bonds + side_bonds_n
n_anglesnew = n_angles + side_angles_n
n_dihednew = n_dihedrals + side_dihed_n
Expand Down Expand Up @@ -341,13 +360,15 @@ def extract_gromacs_data( _data_files_, _autoload_):
# atom tags in index 4
_charge_ = {}
_conv_dict_ = {}

for sb in range( len( sidemol['tag'])):
for at in range( len( sidemol['data'][sb]['atoms'])):
a_opls_tag = sidemol['data'][sb]['atoms'][at][1]
a_elem_tag = sidemol['data'][sb]['atoms'][at][4]
a_charge = float( sidemol['data'][sb]['atoms'][at][6])
_charge_[a_opls_tag] = a_charge
_conv_dict_[ a_elem_tag] = a_opls_tag

print '='*45+'\n'+'='*5+' Charges found: '
print _charge_
print _conv_dict_
Expand Down Expand Up @@ -452,7 +473,8 @@ def extract_gromacs_data( _data_files_, _autoload_):
poss = 4
for i in range( len ( data_container[ nice_list[it] ])):
_aux_set_here.add( data_container[ nice_list[it] ][i][ poss ])
#print _aux_set_here
#print( nice_list[it][:4])
#print(_aux_set_here)
data_container[ nice_list[it][:4]+'_kinds'] = _aux_set_here


Expand All @@ -465,6 +487,8 @@ def extract_gromacs_data( _data_files_, _autoload_):
data_container['numbers']['total'] = [n_atomsnew, n_bondsnew,
n_anglesnew, n_dihednew, n_impropnew
]
#print( 'here', data_container['numbers']['total'])
#exit('')
data_container['numbers']['type'] = [n_atomtypes, n_bondstypes,
n_anglestypes, n_dihedraltypes,
n_impropertypes]
Expand Down
57 changes: 47 additions & 10 deletions lib/handling/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,18 @@ def write_lammps_data_auto( _topodata_, data_name, _config_):
_bond_ty_ = dicts[1][ sm_bonds[i][0]]
except KeyError:
# OPLS ??
at1_tag, at2_tag = sm_bonds[i][0].split('-')
at1_tag = aat_ddic[ at1_tag]
at2_tag = aat_ddic[ at2_tag]
_bond_ty_ = dicts[1][ at1_tag + '-'+ at2_tag]
try:
at1_tag, at2_tag = sm_bonds[i][0].split('-')
#print(at1_tag, at2_tag)
at1_tag = aat_ddic[ at1_tag]
at2_tag = aat_ddic[ at2_tag]
_bond_ty_ = dicts[1][ at1_tag + '-'+ at2_tag]

except KeyError:

print('Bond type not found for:' + sm_bonds[i][0])
print('Or ' + at1_tag + '-'+ at2_tag)
exit( dicts[1] )

_text_ += bond_shape.format(i+1 + base_bonds_n,
_bond_ty_,
Expand Down Expand Up @@ -591,8 +599,19 @@ def write_lammps_data_auto( _topodata_, data_name, _config_):
aux_here = sm_dihedrals[i][0].split('-')
aux_here = [ aat_ddic[ at_tag] for at_tag in aux_here]
_dihe_ty_ = dicts[3][ '-'.join( aux_here)]
except KeyError as Er_here:
err_str = Er_here.args[0]

except KeyError:
options = [ 'X-{}-{}-X'.format( *aux_here[1:-1]),
'X-{}-{}-X'.format( *aux_here[2:0:-1]),
'X-{}-{}-{}'.format( *aux_here[1:]),
'{}-{}-{}-X'.format( *aux_here[:-1]),
]
for _opt_ in options:
try:
_dihe_ty_ = dicts[3][ _opt_]
break
except KeyError as Er_here:
err_str += ' // ' + Er_here.args[0]

if _dihe_ty_ == '0' and err_str <> '':
print( 'Atoms {}-{}-{}-{} '.format( *aux_here) + ' '
Expand Down Expand Up @@ -666,12 +685,30 @@ def write_lammps_data_auto( _topodata_, data_name, _config_):
if _sidemol_f_ == 1:
for i in range( n_impropers - base_impropers_n):
_impr_ty_ = '0'
err_str = ''
try:
_impr_ty_ = dicts[4][ sm_impropers[i][0]]

except KeyError as Er_here:
print( wrg_1('Improper dihedral > ' + Er_here.args[0]
+ ' < not found!')
)

err_str += Er_here.args[0]

aux_here = sm_impropers[i][0].split('-')
options = [aux_here[0] + '-X-X-' + aux_here[3],
aux_here[3] + '-X-X-' + aux_here[0],
]

for _opt_ in options:
try:
_impr_ty_ = dicts[4][ _opt_]

except KeyError as Er_here:
err_str += Er_here.args[0]

if _impr_ty_ == '0' and err_str <> '':
print( wrg_1('Improper dihedral > ' + err_str
+ ' < not found!')
)

_text_ += improper_shape.format( i+1 + base_impropers_n,
_impr_ty_,
Expand Down Expand Up @@ -747,7 +784,7 @@ def write_lammps_potentials( _topodata_, atomstyle = 'full'):
_numbers_ = _topodata_['numbers']
n_atomtypes, n_bondtypes, n_angletypes = _numbers_['type'][:3]
n_dihedraltypes, n_impropertypes = _numbers_['type'][3:]

#exit(_numbers_)
#n_bondstypes = len(data_container['bondtypes'])

buckorlj = int( _topodata_[ 'defaults'][0]) # 1 -2 lj/buc
Expand Down

0 comments on commit f9189fb

Please sign in to comment.