-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
561 additions
and
1,078 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 67 additions & 0 deletions
67
molsysmt/data/databases/saccharides/make_saccharides_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# wget https://files.wwpdb.org/pub/pdb/data/monomers/components.cif | ||
|
||
from molsysmt.native import CIFFileHandler | ||
import pickle | ||
|
||
handler = CIFFileHandler('../components.cif') | ||
cif_entries = handler.parse() | ||
|
||
types_dict = {} | ||
|
||
for ii in cif_entries: | ||
jj = cif_entries[ii]['_chem_comp']['type'] | ||
if jj in types_dict: | ||
types_dict[jj].append(ii) | ||
else: | ||
types_dict[jj] = [ii] | ||
|
||
# Adding only non-polymer and other | ||
types = ['saccharide', 'D-saccharide', '"L-saccharide, beta linking"', '"L-saccharide, alpha linking"', | ||
'D-SACCHARIDE', 'L-saccharide', '"D-saccharide, beta linking"', '"D-saccharide, alpha linking"', | ||
'L-SACCHARIDE', 'SACCHARIDE'] | ||
|
||
data = [] | ||
for ii in types: | ||
data += types_dict[ii] | ||
|
||
output = {} | ||
|
||
for value in data: | ||
|
||
key = cif_entries[value] | ||
|
||
tmp_dict={} | ||
|
||
tmp_dict['name']=key['_chem_comp']['name'] | ||
tmp_dict['topology']=[] | ||
tmp_dict['topology'].append({'atoms':key['_chem_comp_atom']['atom_id'], 'bonds':[]}) | ||
tmp_dict['topology'].append({'atoms':key['_chem_comp_atom']['alt_atom_id'], 'bonds':[]}) | ||
if '_chem_comp_bond' in key: | ||
if not isinstance(key['_chem_comp_bond']['atom_id_1'],list): | ||
key['_chem_comp_bond']['atom_id_1'] = [key['_chem_comp_bond']['atom_id_1']] | ||
key['_chem_comp_bond']['atom_id_2'] = [key['_chem_comp_bond']['atom_id_2']] | ||
for atom1,atom2 in zip(key['_chem_comp_bond']['atom_id_1'], key['_chem_comp_bond']['atom_id_2']): | ||
tmp_dict['topology'][0]['bonds'].append([atom1,atom2]) | ||
ii = tmp_dict['topology'][0]['atoms'].index(atom1) | ||
jj = tmp_dict['topology'][0]['atoms'].index(atom2) | ||
atom1 = tmp_dict['topology'][1]['atoms'][ii] | ||
atom2 = tmp_dict['topology'][1]['atoms'][jj] | ||
tmp_dict['topology'][1]['bonds'].append([atom1,atom2]) | ||
|
||
output[value]=tmp_dict | ||
|
||
split_output = {} | ||
for name,value in output.items(): | ||
if name[0] not in split_output: | ||
split_output[name[0]]={} | ||
split_output[name[0]][name]=value | ||
|
||
import gzip | ||
|
||
for file_name, aux_output in split_output.items(): | ||
with gzip.open(file_name+'.pkl.gz', 'wb', compresslevel=9) as fff: | ||
pickle.dump(aux_output, fff) | ||
|
||
with gzip.open('group_names.pkl.gz', 'wb', compresslevel=9) as fff: | ||
pickle.dump(sorted(list(output.keys())), fff) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from .saccharide_names import saccharide_names | ||
from .is_saccharide import is_saccharide | ||
from .group_names import group_names | ||
from .get_group_db import get_group_db | ||
from .get_bonded_atom_pairs import get_bonded_atom_pairs |
45 changes: 45 additions & 0 deletions
45
molsysmt/element/group/saccharide/get_bonded_atom_pairs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import numpy as np | ||
|
||
_sorted=sorted | ||
|
||
def get_bonded_atom_pairs(group_name, atom_names, atom_indices=None, sorted=True): | ||
|
||
from . import group_names, get_group_db | ||
|
||
if group_name not in group_names: | ||
raise ValueError | ||
|
||
if atom_indices is None: | ||
atom_indices = np.arange(len(atom_names), dtype=int).tolist() | ||
|
||
db = get_group_db(group_name) | ||
|
||
is_in = -1 | ||
for ii,jj in enumerate(db['topology']): | ||
if np.all(np.isin(atom_names, jj['atoms'])): | ||
is_in=ii | ||
break | ||
|
||
if is_in!=-1: | ||
|
||
bonds = [] | ||
for ii,jj in db['topology'][is_in]['bonds']: | ||
if ii in atom_names: | ||
if jj in atom_names: | ||
iii = atom_indices[atom_names.index(ii)] | ||
jjj = atom_indices[atom_names.index(jj)] | ||
if iii<jjj: | ||
bonds.append([iii,jjj]) | ||
else: | ||
bonds.append([jjj,iii]) | ||
|
||
else: | ||
|
||
print(group_name, atom_names) | ||
|
||
raise ValueError | ||
|
||
if sorted: | ||
return _sorted(bonds) | ||
else: | ||
return bonds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pickle | ||
import sys | ||
import gzip | ||
import numpy as np | ||
from molsysmt.element.group.saccharide import group_names | ||
|
||
from importlib.resources import files | ||
def path(package, file): | ||
return files(package).joinpath(file) | ||
|
||
|
||
def get_group_db(group_name): | ||
|
||
if group_name not in group_names: | ||
raise ValueError | ||
|
||
with gzip.open(path('molsysmt.data.databases.saccharides',group_name[0]+'.pkl.gz'), 'rb') as fff: | ||
dbs = pickle.load(fff) | ||
|
||
db = dbs[group_name] | ||
|
||
return db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pickle | ||
import sys | ||
import gzip | ||
|
||
from importlib.resources import files | ||
def path(package, file): | ||
return files(package).joinpath(file) | ||
|
||
try: | ||
with gzip.open(path('molsysmt.data.databases.saccharides','group_names.pkl.gz'), 'rb') as fff: | ||
group_names = pickle.load(fff) | ||
except: | ||
group_names = None | ||
print('The file molsysmt.data.databases.saccharides.group_names.pkl.gz was not loaded.') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from .saccharide_names import saccharide_names | ||
from .group_names import group_names | ||
|
||
def is_saccharide(name): | ||
""" | ||
To be written soon... | ||
""" | ||
|
||
return (name in saccharide_names) | ||
return (name in group_names) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.