def write_to_file(self, filename):
<EOL>if filename.endswith('<STR_LIT>'):<EOL><INDENT>from molmod.io import dump_cml<EOL>dump_cml(filename, [self])<EOL><DEDENT>elif filename.endswith('<STR_LIT>'):<EOL><INDENT>from molmod.io import XYZWriter<EOL>symbols = []<EOL>for n in self.numbers:<EOL><INDENT>atom = periodic[n]<EOL>if atom is None:<EOL><INDENT>symbols.append("<STR_LIT:X>")<EOL><DEDENT>else:<EOL><INDENT>symbols.append(atom.symbol)<EOL><DEDENT><DEDENT>xyz_writer = XYZWriter(filename, symbols)<EOL>xyz_writer.dump(self.title, self.coordinates)<EOL>del xyz_writer<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % filename)<EOL><DEDENT>
Write the molecular geometry to a file.

           The file format is inferred from the extensions. Currently supported
           formats are: ``*.xyz``, ``*.cml``

           Argument:
            | ``filename``  --  a filename