Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new cif files to be read by cif reader #112

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 17 additions & 9 deletions converter_app/readers/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ def check(self):
with ZipFile(self.file.fp, 'r') as zip_obj:
try:
file_name = next(x for x in zip_obj.namelist() if x.lower().endswith(self.file_prefix))
zipdir = os.path.join(tempfile.TemporaryDirectory().name, self.file.name)
os.makedirs(zipdir)
path_file_name = zip_obj.extract(file_name, zipdir)
with open(path_file_name, 'rb') as f:
fs = FileStorage(stream=f, filename=os.path.basename(file_name), content_type='chemical/x-cif')
self.file = File(fs)
with os.path.join(tempfile.TemporaryDirectory().name, self.file.name) as zipdir:
os.makedirs(zipdir)
path_file_name = zip_obj.extract(file_name, zipdir)
with open(path_file_name, 'rb') as f:
fs = FileStorage(stream=f, filename=os.path.basename(file_name),
content_type='chemical/x-cif')
self.file = File(fs)
except:
logger.debug('result=%s', False)
return False
Expand All @@ -63,8 +64,13 @@ def check(self):
if result:
try:
self.cif = cif.read_string(self.file.content) # copy all the data from mmCIF file
except:
result = False
except ValueError as e:
if str(e).endswith('expected block header (data_)'):
content = 'data_' + re.split('^data_', self.file.string, flags=re.M)[-1]
try:
self.cif = cif.read_string(content) # copy all the data from mmCIF file
except ValueError:
result = False

return result

Expand All @@ -83,7 +89,9 @@ def prepare_tables(self):

for item in block:
if item.pair is not None:
if len(item.pair[1]) > self.junk_size_threshold:
if 'highest difference peak' in ''.join(item.pair).lower():
meta_table['header'].append(' = '.join(item.pair[:2]))
elif len(item.pair[1]) > self.junk_size_threshold:
has_junk = True
junk_table_header.append(' = '.join(item.pair[:2]))
else:
Expand Down
2 changes: 1 addition & 1 deletion requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gunicorn~=20.1.0
openpyxl~=3.0.9
python-dotenv~=0.19.2
python-magic~=0.4.24
gemmi~=0.5.7
gemmi~=0.6.6
xlrd~=2.0.1
Werkzeug~=2.2.2
jcamp~=1.2.2
Expand Down
Loading
Loading