Skip to content

Commit

Permalink
Parser tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Nov 8, 2018
1 parent d352c5e commit 7c424e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions crystals/crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, unitcell, lattice_vectors, source = None, **kwargs):

@classmethod
@lru_cache(maxsize = len(builtins), typed = True) # saves a lot of time in tests
def from_cif(cls, path):
def from_cif(cls, path, **kwargs):
"""
Returns a Crystal object created from a CIF 1.0, 1.1 or 2.0 file.
Expand All @@ -102,13 +102,13 @@ def from_cif(cls, path):
.. [#] Torbjorn Bjorkman, "CIF2Cell: Generating geometries for electronic structure programs",
Computer Physics Communications 182, 1183-1186 (2011). doi: 10.1016/j.cpc.2011.01.013
"""
with CIFParser(filename = path) as parser:
with CIFParser(filename = path, **kwargs) as parser:
return cls(unitcell = symmetry_expansion(parser.atoms(), parser.symmetry_operators()),
lattice_vectors = parser.lattice_vectors(),
source = str(path))

@classmethod
def from_database(cls, name):
def from_database(cls, name, **kwargs):
"""
Returns a Crystal object create from the internal CIF database.
Expand All @@ -123,10 +123,10 @@ def from_database(cls, name):
)

path = Path(__file__).parent / 'cifs' / (name + '.cif')
return cls.from_cif(path)
return cls.from_cif(path, **kwargs)

@classmethod
def from_cod(cls, num, revision = None, download_dir = None, overwrite = False):
def from_cod(cls, num, revision = None, download_dir = None, overwrite = False, **kwargs):
"""
Returns a Crystal object built from the Crystallography Open Database.
Expand All @@ -142,13 +142,13 @@ def from_cod(cls, num, revision = None, download_dir = None, overwrite = False):
Whether or not to overwrite files in cache if they exist. If no revision
number is provided, files will always be overwritten.
"""
with CODParser(num, revision, download_dir, overwrite) as parser:
with CODParser(num, revision, download_dir, overwrite, **kwargs) as parser:
return cls(unitcell = symmetry_expansion(parser.atoms(), parser.symmetry_operators()),
lattice_vectors = parser.lattice_vectors(),
source = 'COD num:{n} rev:{r}'.format(n = num, r = revision))

@classmethod
def from_pdb(cls, ID, download_dir = None, overwrite = False):
def from_pdb(cls, ID, download_dir = None, overwrite = False, **kwargs):
"""
Returns a Crystal object created from a Protein DataBank entry.
Expand All @@ -163,7 +163,7 @@ def from_pdb(cls, ID, download_dir = None, overwrite = False):
Whether or not to overwrite files in cache if they exist. If no revision
number is provided, files will always be overwritten.
"""
with PDBParser(ID = ID, download_dir = download_dir) as parser:
with PDBParser(ID = ID, download_dir = download_dir, **kwargs) as parser:
return cls(unitcell = symmetry_expansion(parser.atoms(), parser.symmetry_operators()),
lattice_vectors = parser.lattice_vectors(),
source = parser.filename)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import namedtuple
from contextlib import suppress
from pathlib import Path
from tempfile import gettempdir
from warnings import catch_warnings
from warnings import filterwarnings

Expand Down Expand Up @@ -79,7 +80,7 @@ class TestPDBParserAgainstBioPython(unittest.TestCase):
test_ids = ('1fbb', '1fat', '1gzx')

def setUp(self):
self.pdb_list = biopdb.PDBList()
self.pdb_list = biopdb.PDBList(verbose=False, obsolete_pdb=gettempdir())
self.biopdb_parser = biopdb.PDBParser()

def test_chemical_composition(self):
Expand Down

0 comments on commit 7c424e8

Please sign in to comment.