Skip to content

Commit

Permalink
look for cif and emd in path
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmkrieger committed Nov 8, 2023
1 parent 27e38ba commit fe56a70
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
6 changes: 5 additions & 1 deletion prody/proteins/ciffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parseMMCIF(pdb, **kwargs):
auto_bonds = SETTINGS.get('auto_bonds')
get_bonds = kwargs.get('bonds', auto_bonds)
if get_bonds:
LOGGER.warn('Parsing struct_conn information from mmCIF is current unsupported and no bond information is added to the results')
LOGGER.warn('Parsing struct_conn information from mmCIF is currently unsupported and no bond information is added to the results')
if not os.path.isfile(pdb):
if len(pdb) == 5 and pdb.isalnum():
if chain is None:
Expand All @@ -105,8 +105,12 @@ def parseMMCIF(pdb, **kwargs):

if os.path.isfile(pdb + '.cif'):
filename = pdb + '.cif'
LOGGER.debug('CIF file is found in working directory ({0}).'
.format(filename))
elif os.path.isfile(pdb + '.cif.gz'):
filename = pdb + '.cif.gz'
LOGGER.debug('CIF file is found in working directory ({0}).'
.format(filename))
else:
filename = fetchPDB(pdb, report=True,
format='cif', compressed=False)
Expand Down
12 changes: 12 additions & 0 deletions prody/proteins/emdfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ def parseEMD(emd, **kwargs):

if os.path.isfile(emd + '.map'):
filename = emd + '.map'
LOGGER.debug('EMD file is found in working directory ({0}).'
.format(filename))
elif os.path.isfile(emd + '.map.gz'):
filename = emd + '.map.gz'
LOGGER.debug('EMD file is found in working directory ({0}).'
.format(filename))
else:
filename = fetchPDB(emd, report=True,
format='emd', compressed=False)
Expand All @@ -91,6 +95,14 @@ def parseEMD(emd, **kwargs):
result = parseEMDStream(emdStream, **kwargs)
emdStream.close()

if hasattr(result, 'numAtoms'):
LOGGER.info('Output is an AtomGroup with {0} atoms fitted.'.format(result.numAtoms()))
elif hasattr(result, 'apix'):
LOGGER.info('Output is an EMDMAP with {:4.2f} A/pix.'.format(result.apix[0]))
else:
LOGGER.warn('Atomic data could not be parsed, please '
'check the input file.')

return result


Expand Down
27 changes: 20 additions & 7 deletions prody/proteins/localpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,15 @@ def fetchPDB(*pdb, **kwargs):
if len(pdb) == 1 and isinstance(pdb[0], list):
pdb = pdb[0]

if 'format' in kwargs and kwargs.get('format') != 'pdb':
return fetchPDBviaFTP(*pdb, **kwargs)

identifiers = checkIdentifiers(*pdb)

folder = kwargs.get('folder', '.')
compressed = kwargs.get('compressed')
format = kwargs.get('format')

# check *folder* specified by the user, usually pwd ('.')
filedict = findPDBFiles(folder, compressed=compressed)
filedict = findPDBFiles(folder, compressed=compressed,
format=format)

filenames = []
not_found = []
Expand All @@ -232,6 +231,8 @@ def fetchPDB(*pdb, **kwargs):
elif pdb in filedict:
filenames.append(filedict[pdb])
exists += 1
LOGGER.debug('{0} file is found in working directory ({1}).'
.format(format.upper(), sympath(filedict[pdb])))
else:
filenames.append(None)
not_found.append((i, pdb))
Expand All @@ -240,8 +241,8 @@ def fetchPDB(*pdb, **kwargs):
if len(filenames) == 1:
filenames = filenames[0]
if exists:
LOGGER.debug('PDB file is found in working directory ({0}).'
.format(sympath(filenames)))
LOGGER.debug('{0} file is found in working directory ({1}).'
.format(format.upper(), sympath(filedict[pdb])))
return filenames

if not isWritable(folder):
Expand Down Expand Up @@ -414,6 +415,8 @@ def iterPDBFilenames(path=None, sort=False, unique=True, **kwargs):

from re import compile, IGNORECASE

format = kwargs.get('format')

if path is None or kwargs.get('mirror') is True:
if path is None:
path = pathPDBMirror()
Expand All @@ -436,10 +439,20 @@ def iterPDBFilenames(path=None, sort=False, unique=True, **kwargs):
compressed = kwargs.get('compressed')
if compressed is None:
pdbext = compile('\.(pdb|ent)(\.gz)?$', IGNORECASE)
cifext = compile('\.(cif)(\.gz)?$', IGNORECASE)
emdext = compile('\.(emd|map|mrc)(\.gz)?$', IGNORECASE)
elif compressed:
pdbext = compile('\.(pdb|ent)\.gz$', IGNORECASE)
cifext = compile('\.(cif)\.gz$', IGNORECASE)
emdext = compile('\.(emd|map|mrc)\.gz$', IGNORECASE)
else:
pdbext = compile('\.(pdb|ent)$', IGNORECASE)
cifext = compile('\.(cif)$', IGNORECASE)
emdext = compile('\.(emd|map|mrc)$', IGNORECASE)
if format == 'cif':
pdbext = cifext
if format == 'emd':
pdbext = emdext
pdbs = [pdb for pdb in iglob(join(path, '*')) if pdbext.search(pdb)]
if sort:
pdbs.sort(reverse=kwargs.get('reverse'))
Expand Down Expand Up @@ -476,7 +489,7 @@ def findPDBFiles(path, case=None, **kwargs):
pdb = splitext(split(fn)[1])[0]
ending = splitext(splitext(split(fn)[1])[0])[1]
if ending == 'gz':
pdb = splittext(pdb)[0]
pdb = splitext(pdb)[0]
if len(pdb) == 7 and pdb.startswith('pdb'):
pdb = pdb[3:]
if upper:
Expand Down

0 comments on commit fe56a70

Please sign in to comment.