From 53bd4432f967d9ffcc15bad10baeb239b9f87f39 Mon Sep 17 00:00:00 2001 From: haidi Date: Mon, 7 Oct 2019 15:22:55 +0800 Subject: [PATCH] build surface by using ASE interface --- README.md | 4 ++-- dpgen/auto_test/__init__.py | 0 dpgen/auto_test/lib/__init__.py | 0 dpgen/data/surf.py | 25 +++++++++++++++++++------ dpgen/data/tools/__init__.py | 0 dpgen/data/tools/bcc.py | 2 +- dpgen/dispatcher/__init__.py | 0 dpgen/main.py | 4 ++-- tests/data/surf-100.POSCAR | 32 +++++++++++++++++++------------- tests/data/surf.json | 2 +- 10 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 dpgen/auto_test/__init__.py create mode 100644 dpgen/auto_test/lib/__init__.py create mode 100644 dpgen/data/tools/__init__.py create mode 100644 dpgen/dispatcher/__init__.py diff --git a/README.md b/README.md index efe8a0bfe..da2fe8427 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ Following is an example for `PARAM`, which generates data from a typical structu 2, 2 ], - "z_min": 9, + "layer_numb": 3, "vacuum_max": 9, "vacuum_resol": [ 0.5, @@ -251,7 +251,7 @@ The bold notation of key (such as **Elements**) means that it's a necessary key. | **Elements** | List of String | ["Mg"] | Atom types | **cell_type** | String | "hcp" | Specifying which typical structure to be generated. **Options** include fcc, hcp, bcc, sc, diamond. | **latt** | Float | 4.479 | Lattice constant for single cell. -| **z_min** | Float | 9 | Thickness of slab (Angstrom). +| **layer_numb** | Integer | 3 | Number of equavilent layers of slab. | **vacuum_max** | Float | 9 | Maximal thickness of vacuum (Angstrom). | **vacuum_resol** | List of float | [0.5, 1 ] | Interval of thichness of vacuum. If size of `vacuum_resol` is 1, the interval is fixed to its value. If size of `vacuum_resol` is 2, the interval is `vacuum_resol[0]` before `mid_point`, otherwise `vacuum_resol[1]` after `mid_point`. | **millers** | List of list of Integer | [[1,0,0]] | Miller indices. diff --git a/dpgen/auto_test/__init__.py b/dpgen/auto_test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/dpgen/auto_test/lib/__init__.py b/dpgen/auto_test/lib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 641511a9b..81753df5e 100755 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -15,6 +15,11 @@ from dpgen.remote.RemoteJob import SSHSession, JobStatus, SlurmJob, PBSJob, CloudMachineJob from pymatgen.core.surface import SlabGenerator,generate_all_slabs, Structure from pymatgen.io.vasp import Poscar +#-----ASE------- +from pymatgen.io.ase import AseAtomsAdaptor +from ase.io import read +from ase.build import general_surface + def create_path (path) : path += '/' @@ -195,10 +200,16 @@ def make_super_cell_pymatgen (jdata) : from_path = path_uc from_file = os.path.join(from_path, 'POSCAR.unit') ss = Structure.from_file(from_file) + # ase only support X type element + for i in range(len(ss)): + ss[i]='X' + ss=AseAtomsAdaptor.get_atoms(ss) + all_millers = jdata['millers'] path_sc = os.path.join(out_dir, global_dirname_02) - z_min = jdata['z_min'] + #z_min = jdata['z_min'] + layer_numb = jdata['layer_numb'] super_cell = jdata['super_cell'] cwd = os.getcwd() @@ -211,11 +222,13 @@ def make_super_cell_pymatgen (jdata) : miller_str += str(ii) path_cur_surf = create_path('surf-'+miller_str) os.chdir(path_cur_surf) - slabgen = SlabGenerator(ss, miller, z_min, 1e-3) - all_slabs = slabgen.get_slabs() + #slabgen = SlabGenerator(ss, miller, z_min, 1e-3) + slab=general_surface.surface(ss,indices=miller,vacuum=1e-3,layers=layer_numb) + #all_slabs = slabgen.get_slabs() dlog.info(os.getcwd()) - dlog.info("Miller %s: The slab has %s termination, use the first one" %(str(miller), len(all_slabs))) - all_slabs[0].to('POSCAR', 'POSCAR') + #dlog.info("Miller %s: The slab has %s termination, use the first one" %(str(miller), len(all_slabs))) + #all_slabs[0].to('POSCAR', 'POSCAR') + slab.write('POSCAR',vasp5=True) if super_cell[0] > 1 or super_cell[1] > 1 : st=Structure.from_file('POSCAR') st.make_supercell([super_cell[0], super_cell[1], 1]) @@ -408,7 +421,7 @@ def pert_scaled(jdata) : tail_elongs = np.arange(mid_point, vacuum_max, vacuum_resol[1]).tolist() elongs = np.unique(head_elongs+tail_elongs).tolist() else: - raise RuntimeError("the length of vacuum_resol must equal 2") + raise RuntimeError("the length of vacuum_resol must equal 1 or 2") else: vacuum_num = jdata['vacuum_numb'] diff --git a/dpgen/data/tools/__init__.py b/dpgen/data/tools/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/dpgen/data/tools/bcc.py b/dpgen/data/tools/bcc.py index 02b7d5d3a..e02483b32 100644 --- a/dpgen/data/tools/bcc.py +++ b/dpgen/data/tools/bcc.py @@ -9,7 +9,7 @@ def gen_box () : def poscar_unit (latt) : box = gen_box() ret = "" - ret += "FCC : a = %f \n" % latt + ret += "BCC : a = %f \n" % latt ret += "%.16f\n" % (latt) ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2]) ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2]) diff --git a/dpgen/dispatcher/__init__.py b/dpgen/dispatcher/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/dpgen/main.py b/dpgen/main.py index ae4f57250..f5b03a9b5 100644 --- a/dpgen/main.py +++ b/dpgen/main.py @@ -105,8 +105,8 @@ def main(): help="Collecting data from Deep Generator.") parser_db.add_argument('PATH', type=str, help="root path for dpgen modeling") - parser_db.add_argument('CALCULATOR', type=str, - help="calculator used for labeling: vasp/pwscf/gaussian") + parser_db.add_argument('ENGINE', type=str, + help="engine used for labeling: vasp/pwscf/cp2k/gaussian/siesta") parser_db.add_argument('OUTPUT', type=str, help="output filename : file.json/file.yaml") parser_db.add_argument("ID_PREFIX", type=str, default=None, diff --git a/tests/data/surf-100.POSCAR b/tests/data/surf-100.POSCAR index f9ee253b3..22073df90 100644 --- a/tests/data/surf-100.POSCAR +++ b/tests/data/surf-100.POSCAR @@ -1,14 +1,20 @@ -Type6 -1.0 -2.899138 0.000000 0.000000 -0.000000 2.899138 0.000000 -0.000000 0.000000 16.400000 + X + 1.0000000000000000 + 4.0999999999999996 0.0000000000000000 0.0000000000000000 + 0.0000000000000000 4.0999999999999996 0.0000000000000000 + 0.0000000000000000 0.0000000000000000 10.2520000000000007 Al -6 -direct -0.000000 0.000000 0.812500 Type0+ -0.000000 0.000000 0.312500 Type0+ -0.500000 0.500000 0.937500 Type0+ -0.000000 0.000000 0.562500 Type0+ -0.500000 0.500000 0.687500 Type0+ -0.500000 0.500000 0.437500 Type0+ +12 +Cartesian + 2.0499999999999998 2.0499999999999998 4.1010000000000000 + 0.0000000000000000 2.0499999999999998 6.1509999999999998 + 0.0000000000000000 0.0000000000000000 4.1010000000000000 + 0.0000000000000000 0.0000000000000000 8.2010000000000005 + 2.0499999999999998 2.0499999999999998 8.2010000000000005 + 2.0499999999999998 0.0000000000000000 10.2510000000000012 + 2.0499999999999998 0.0000000000000000 2.0510000000000002 + 0.0000000000000000 2.0499999999999998 10.2510000000000012 + 2.0499999999999998 0.0000000000000000 6.1509999999999998 + 2.0499999999999998 2.0499999999999998 0.0010000000000003 + 0.0000000000000000 2.0499999999999998 2.0510000000000002 + 0.0000000000000000 0.0000000000000000 0.0010000000000003 diff --git a/tests/data/surf.json b/tests/data/surf.json index 1f22f2bab..63c7bc418 100644 --- a/tests/data/surf.json +++ b/tests/data/surf.json @@ -10,7 +10,7 @@ 1, 1 ], - "z_min": 9, + "layer_numb": 3, "vacuum_max": 9, "vacuum_resol": [ 0.5,