@@ -1250,7 +1250,7 @@ def clone(self, memo: Optional[dict] = None) -> Material:
12501250
12511251 return memo [self ]
12521252
1253- def _get_nuclide_xml (self , nuclide : str ) -> ET .Element :
1253+ def _get_nuclide_xml (self , nuclide : NuclideTuple ) -> ET .Element :
12541254 xml_element = ET .Element ("nuclide" )
12551255 xml_element .set ("name" , nuclide .name )
12561256
@@ -1267,15 +1267,28 @@ def _get_macroscopic_xml(self, macroscopic: str) -> ET.Element:
12671267
12681268 return xml_element
12691269
1270- def _get_nuclides_xml (self , nuclides : typing .Iterable [str ]) -> List [ET .Element ]:
1270+ def _get_nuclides_xml (
1271+ self , nuclides : typing .Iterable [NuclideTuple ],
1272+ nuclides_to_ignore : Optional [typing .Iterable [str ]] = None )-> List [ET .Element ]:
12711273 xml_elements = []
1272- for nuclide in nuclides :
1273- xml_elements .append (self ._get_nuclide_xml (nuclide ))
1274+
1275+ # Remove any nuclides to ignore from the XML export
1276+ if nuclides_to_ignore :
1277+ nuclides = [nuclide for nuclide in nuclides if nuclide .name not in nuclides_to_ignore ]
1278+
1279+ xml_elements = [self ._get_nuclide_xml (nuclide ) for nuclide in nuclides ]
1280+
12741281 return xml_elements
12751282
1276- def to_xml_element (self ) -> ET .Element :
1283+ def to_xml_element (
1284+ self , nuclides_to_ignore : Optional [typing .Iterable [str ]] = None ) -> ET .Element :
12771285 """Return XML representation of the material
12781286
1287+ Parameters
1288+ ----------
1289+ nuclides_to_ignore : list of str
1290+ Nuclides to ignore when exporting to XML.
1291+
12791292 Returns
12801293 -------
12811294 element : lxml.etree._Element
@@ -1320,7 +1333,8 @@ def to_xml_element(self) -> ET.Element:
13201333
13211334 if self ._macroscopic is None :
13221335 # Create nuclide XML subelements
1323- subelements = self ._get_nuclides_xml (self ._nuclides )
1336+ subelements = self ._get_nuclides_xml (self ._nuclides ,
1337+ nuclides_to_ignore = nuclides_to_ignore )
13241338 for subelement in subelements :
13251339 element .append (subelement )
13261340 else :
@@ -1576,7 +1590,8 @@ def make_isotropic_in_lab(self):
15761590 for material in self :
15771591 material .make_isotropic_in_lab ()
15781592
1579- def _write_xml (self , file , header = True , level = 0 , spaces_per_level = 2 , trailing_indent = True ):
1593+ def _write_xml (self , file , header = True , level = 0 , spaces_per_level = 2 ,
1594+ trailing_indent = True , nuclides_to_ignore = None ):
15801595 """Writes XML content of the materials to an open file handle.
15811596
15821597 Parameters
@@ -1591,6 +1606,8 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2, trailing_in
15911606 Number of spaces per indentation
15921607 trailing_indentation : bool
15931608 Whether or not to write a trailing indentation for the materials element
1609+ nuclides_to_ignore : list of str
1610+ Nuclides to ignore when exporting to XML.
15941611
15951612 """
15961613 indentation = level * spaces_per_level * ' '
@@ -1611,7 +1628,7 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2, trailing_in
16111628
16121629 # Write the <material> elements.
16131630 for material in sorted (self , key = lambda x : x .id ):
1614- element = material .to_xml_element ()
1631+ element = material .to_xml_element (nuclides_to_ignore = nuclides_to_ignore )
16151632 clean_indentation (element , level = level + 1 )
16161633 element .tail = element .tail .strip (' ' )
16171634 file .write ((level + 1 )* spaces_per_level * ' ' )
@@ -1626,13 +1643,16 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2, trailing_in
16261643 if trailing_indent :
16271644 file .write (indentation )
16281645
1629- def export_to_xml (self , path : PathLike = 'materials.xml' ):
1646+ def export_to_xml (self , path : PathLike = 'materials.xml' ,
1647+ nuclides_to_ignore : Optional [typing .Iterable [str ]] = None ):
16301648 """Export material collection to an XML file.
16311649
16321650 Parameters
16331651 ----------
16341652 path : str
16351653 Path to file to write. Defaults to 'materials.xml'.
1654+ nuclides_to_ignore : list of str
1655+ Nuclides to ignore when exporting to XML.
16361656
16371657 """
16381658 # Check if path is a directory
@@ -1645,7 +1665,7 @@ def export_to_xml(self, path: PathLike = 'materials.xml'):
16451665 # one go.
16461666 with open (str (p ), 'w' , encoding = 'utf-8' ,
16471667 errors = 'xmlcharrefreplace' ) as fh :
1648- self ._write_xml (fh )
1668+ self ._write_xml (fh , nuclides_to_ignore = nuclides_to_ignore )
16491669
16501670 @classmethod
16511671 def from_xml_element (cls , elem ) -> Material :
0 commit comments