[ase-users] Converting different format files

Ask Hjorth Larsen asklarsen at gmail.com
Tue Feb 13 19:37:14 CET 2018


Hi,

2018-02-13 16:43 GMT+01:00 Matt Addicoat via ase-users
<ase-users at listserv.fysik.dtu.dk>:
> Hi Rasoul,
>
>
> A basic script can convert files using ASE. I've written one below. You'll
> need argparse as well as ASE. Be careful, it doesn't do any error checking
> in case one format cannot be converted to some other.
>
>
> #!/usr/bin/python
> from ase.atom import Atom
> from ase.atoms import Atoms
>
> from ase.io import read, write
> import argparse
> import os
>
> parser = argparse.ArgumentParser(description="Translate any ASE-readable
> file to any ASE-writable format")
> parser.add_argument('inputfile', nargs="?", type=str, default="in.xyz",
>                                    help="input file, default=in.xyz")
> parser.add_argument("-o", "--output-extn", type=str, default="gen",
>                            help="extn (format) for the output molecule,
> default=gen")
>
> args = parser.parse_args()
>
> file_name, file_extension = os.path.splitext(args.inputfile)
>
> output=file_name+'.'+args.output_extn
>
>
> mol = read(args.inputfile)
> write(output,mol)
>
>
> ---
>
> Save the script somewhere (e.g. myconvert.py) then you would use it by:
> myconvert.py -o gen structure.xyz
>
>
> Warm regards,
>
> Matt
>
>
> On 13/02/2018 15:10, Rasoul Khaledialidusti via ase-users wrote:
>
> To be honest, I have installed ASE and run the ase test successfully.
> But, I am wondering how I could use the capability of converting different
> file formats using ASE.
>
> I would appreciate you if you teach me the procedure of concerting files
> using ASE.

The GUI can also be used to convert files:

  ase gui filename -o newfilename

where formats are guessed from extensions or otherwise.

Next version of ASE (due to be released .... a couple of weeks ago,
but I/we would still like to fix a few things) will do this more
elegantly with the new 'ase convert' command.

Best regards
Ask

>
> Thanks a lot,
>
> Sincerely,
> Rasoul
>
>
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>
>
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users


More information about the ase-users mailing list