File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -234,13 +234,18 @@ def _get_atom_setters(cifloop):
234234 # normal methods
235235 ########################################################################
236236
237- def __init__ (self ):
237+ def __init__ (self , eps = None ):
238+ """Initialize the parser for CIF structure files.
239+
240+ eps -- fractional coordinates cutoff for duplicate positions.
241+ When None use the default for ExpandAsymmetricUnit.
242+ """
238243 StructureParser .__init__ (self )
239244 self .format = "cif"
240245 self .ciffile = None
241246 self .stru = None
242247 self .spacegroup = None
243- self .eps = None
248+ self .eps = eps
244249 self .eau = None
245250 self .asymmetric_unit = None
246251 self .labelindex = {}
@@ -722,7 +727,12 @@ def restoreParserOutput(self):
722727 return
723728
724729
725- def getParser ():
726- return P_cif ()
730+ def getParser (eps = None ):
731+ """Return new parser object for CIF structure format.
732+
733+ eps -- fractional coordinates cutoff for duplicate positions.
734+ When None use the default for ExpandAsymmetricUnit.
735+ """
736+ return P_cif (eps = eps )
727737
728738# End of file
Original file line number Diff line number Diff line change 3535from diffpy .Structure .Parsers .structureparser import StructureParser
3636from diffpy .Structure .Parsers .parser_index_mod import parser_index
3737
38- def getParser (format ):
38+ def getParser (format , ** kw ):
3939 """Return Parser instance for a given structure format.
40+
41+ kw -- keyword arguments passed to the Parser init function.
42+
4043 Raises StructureFormatError exception when format is not defined.
4144 """
4245 if format not in parser_index :
@@ -46,7 +49,7 @@ def getParser(format):
4649 pm = None
4750 import_cmd = 'from diffpy.Structure.Parsers import %s as pm' % pmod
4851 exec (import_cmd )
49- return pm .getParser ()
52+ return pm .getParser (** kw )
5053
5154def inputFormats ():
5255 """Return list of implemented input structure formats"""
Original file line number Diff line number Diff line change 2020
2121from diffpy .Structure .tests .testutils import datafile
2222from diffpy .Structure .Parsers .P_cif import P_cif , leading_float , getSymOp
23+ from diffpy .Structure .Parsers import getParser
2324from diffpy .Structure import Structure
2425from diffpy .Structure import StructureFormatError
2526
@@ -232,6 +233,19 @@ def test_eps(self):
232233 self .assertEqual (4 , len (grph2 ))
233234 return
234235
236+ def test_getParser (self ):
237+ """Test passing of eps keyword argument by getParser function.
238+ """
239+ pcif = getParser ('cif' , eps = 1e-6 )
240+ grph = pcif .parseFile (self .graphiteciffile )
241+ self .assertEqual (8 , len (grph ))
242+ self .assertTrue (all (a .label .startswith ('C1' ) for a in grph [:2 ]))
243+ self .assertTrue (all (a .label .startswith ('C2' ) for a in grph [2 :]))
244+ pcif2 = getParser ('cif' )
245+ grph2 = pcif2 .parseFile (self .graphiteciffile )
246+ self .assertEqual (4 , len (grph2 ))
247+ return
248+
235249 ########################################################################
236250 # helpers
237251 ########################################################################
You can’t perform that action at this time.
0 commit comments