def main():
    """
    Run everythin from the command line
    """

    # Command line parsing
    args = define_options(sys.argv[1:])

    try:
        title, atoms, box = groIO.parse_file(args.filin)
    except groIO.FormatError as e:
        print(e, file=sys.stderr)
        return 1

    if args.verbose:
        print("The input coordinate file is {0}".format(args.filin))
        print("The output file will be {0}".format(args.filout))
        print("The reference atom for the lipid bilayer is {0}".format(
            args.lipid_atom))
        print("The reference atom for the water is {0}".format(
            args.water_atom))

    try:
        if args.sphere is None:
            output_atoms, nb_water = perform_bilayer_removing(
                atoms, args.lipid_atom, args.water_atom, args.verbose)
        else:
            output_atoms, nb_water = perform_sphere_removing(
                atoms, args.sphere, args.radius, args.water_residue,
                args.verbose)

        if args.verbose:
            print()

        print("The old system contained {0} atoms.".format(len(atoms)))
        print("{0} water molecules have been removed.".format(nb_water))
        print("The new system contains {0} atoms.".format(len(output_atoms)))

        # Write in the output file
        with open(args.filout, "w") as fout:
            for line in groIO.write_gro(title, output_atoms, box):
                print(line, end='', file=fout)

    except RefObjectError as e:
        print(e)
        return 1

    return 0
def main():
    """
    Run everythin from the command line
    """

    # Command line parsing
    args = define_options(sys.argv[1:])

    try:
        title, atoms, box = groIO.parse_file(args.filin)
    except groIO.FormatError as e:
        print(e, file=sys.stderr)
        return 1

    if args.verbose:
        print("The input coordinate file is {0}".format(args.filin))
        print("The output file will be {0}".format(args.filout))
        print("The reference atom for the lipid bilayer is {0}".format(args.lipid_atom))
        print("The reference atom for the water is {0}".format(args.water_atom))

    try:
        if args.sphere is None:
            output_atoms, nb_water = perform_bilayer_removing(atoms, args.lipid_atom,
                                                              args.water_atom, args.verbose)
        else:
            output_atoms, nb_water = perform_sphere_removing(atoms, args.sphere, args.radius,
                                                             args.water_residue, args.verbose)

        if args.verbose:
            print()

        print("The old system contained {0} atoms.".format(len(atoms)))
        print("{0} water molecules have been removed.".format(nb_water))
        print("The new system contains {0} atoms.".format(len(output_atoms)))

        # Write in the output file
        with open(args.filout, "w") as fout:
            for line in groIO.write_gro(title, output_atoms, box):
                print(line, end='', file=fout)

    except RefObjectError as e:
        print(e)
        return 1

    return 0
Beispiel #3
0
    def test_write(self):
        """
        Test the writing of a gro file
        """

        # Create a random file
        title, atoms, box = _generate_file()

        # Write it
        test_write = os.path.join(REFDIR, "test_write.gro")
        with open(test_write, "w") as fout:
            for line in groIO.write_gro(title, atoms, box):
                print(line, end='', file=fout)

        # Reference file
        ref_write = os.path.join(REFDIR, "write.gro")

        with open(ref_write) as f1, open(test_write) as f2:
            ref_readlines = f1.readlines()
            test_readlines = f2.readlines()

            self.assertEqual(ref_readlines, test_readlines)

        os.remove(test_write)