Пример #1
0
 def test_Mcsqs_Caller_supercell(self):
     struc = self.struc.copy()
     struc.replace_species({
         'Ti': {
             'Ti': 0.5,
             'Zr': 0.5
         },
         'Zr': {
             'Ti': 0.5,
             'Zr': 0.5
         }
     })
     sqs = run_mcsqs(struc, {
         2: 6,
         3: 4
     },
                     supercell=[2, 1, 1],
                     total_atoms=None,
                     search_time=0.01)
     self.assertEqual(atat.Mcsqs(sqs).to_string() in self.pztstrings, True)
     os.remove('sqscell.out')
     os.remove('rndstrgrp.out')
     os.remove('bestcorr.out')
     os.remove('rndstr.in')
     os.remove('sym.out')
     os.remove('mcsqs.log')
     os.remove('bestsqs.out')
     os.remove('clusters.out')
Пример #2
0
    def test_apply_transformation(self):
        # non-sensical example just for testing purposes
        self.pztstrings = np.load(os.path.join(test_dir,
                                               "mcsqs/pztstrings.npy"),
                                  allow_pickle=True)
        self.struct = self.get_structure('Pb2TiZrO6')

        trans = SQSTransformation({
            2: 6,
            3: 4
        },
                                  supercell=[2, 1, 1],
                                  total_atoms=None,
                                  search_time=0.01)
        struct = self.struct.copy()
        struct.replace_species({
            'Ti': {
                'Ti': 0.5,
                'Zr': 0.5
            },
            'Zr': {
                'Ti': 0.5,
                'Zr': 0.5
            }
        })
        sqs = trans.apply_transformation(struct)
        self.assertEqual(atat.Mcsqs(sqs).to_string() in self.pztstrings, True)
        os.remove('sqscell.out')
        os.remove('rndstrgrp.out')
        os.remove('bestcorr.out')
        os.remove('rndstr.in')
        os.remove('sym.out')
        os.remove('mcsqs.log')
        os.remove('bestsqs.out')
        os.remove('clusters.out')
Пример #3
0
 def test_Mcsqs_Caller_total_atoms(self):
     struc = self.struc.copy()
     struc.replace_species({
         "Ti": {
             "Ti": 0.5,
             "Zr": 0.5
         },
         "Zr": {
             "Ti": 0.5,
             "Zr": 0.5
         }
     })
     sqs = run_mcsqs(struc, {2: 6, 3: 4}, total_atoms=20, search_time=0.01)
     self.assertEqual(atat.Mcsqs(sqs).to_string() in self.pztstrings2, True)
Пример #4
0
def run_mcsqs(structure,
              clusters,
              supercell=None,
              total_atoms=None,
              search_time=0.01):
    """
    Helper function for calling mcsqs with different arguments

    Args:
        clusters (dict): dictionary of cluster interactions with entries in the form
        # atoms: cutoff in angstroms
        supercell (list): dimensions of the supercell in units of the original unit cell
        total_atoms(int): total number of atoms in the final SQS. Choose either
        this OR supercell
        search_time (int): The time spent looking for the ideal SQS in minutes

    Returns:
        Pymatgen structure which is an SQS of the input structure
    """
    num_atoms = len(structure)
    if total_atoms is None:
        total_atoms = num_atoms

    if supercell is not None and total_atoms != num_atoms:
        print("pick supercell OR number of atoms")
        return

    # Set supercell
    cell = np.eye(3)
    text_file = open("sqscell.out", "w")
    text_file.write("1\n")
    for i in range(len(cell)):
        text_file.write("\n")
        for j in range(len(cell[i])):
            text_file.write(str(cell[i][j]) + " ")
    text_file.close()
    struccopy = structure.copy()

    if supercell is not None:
        struccopy.make_supercell(supercell)
        struc = atat.Mcsqs(struccopy)
        text_file = open("rndstr.in", "w")
        text_file.write(struc.to_string())
        text_file.close()

        # Generate Clusters
        command = ["mcsqs"]
        for num in clusters:
            command.append("-" + str(num) + "=" + str(clusters[num]))

        p = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            close_fds=True,
        )
        p.communicate()

        command = ["mcsqs", "-rc", "-n {}".format(len(structure))]
        p = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            close_fds=True,
        )
        try:
            p.communicate(timeout=search_time * 60)
        except subprocess.TimeoutExpired:
            p.kill()
            p.communicate()
            if os.path.exists("bestsqs.out"):
                text_file = open("bestsqs.out", "r")
                bestsqs = text_file.read()
                text_file.close()

                return atat.Mcsqs.structure_from_string(bestsqs)
            else:
                raise TimeoutError("Cluster expansion took too long.")

    else:
        struc = atat.Mcsqs(struccopy)
        text_file = open("rndstr.in", "w")
        text_file.write(struc.to_string())
        text_file.close()

        # Generate Clusters
        command = ["mcsqs"]
        for num in clusters:
            command.append("-" + str(num) + "=" + str(clusters[num]))

        p = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            close_fds=True,
        )
        p.communicate()

        command = ["mcsqs", "-n {}".format(total_atoms)]
        p = subprocess.Popen(
            command,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
            close_fds=True,
        )
        try:
            p.communicate(timeout=search_time * 60)
        except subprocess.TimeoutExpired:
            p.kill()
            p.communicate()
            if os.path.exists("bestsqs.out"):
                text_file = open("bestsqs.out", "r")
                bestsqs = text_file.read()
                text_file.close()

                return atat.Mcsqs.structure_from_string(bestsqs)
            else:
                raise TimeoutError("Cluster expansion took too long.")