Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

# coding: utf-8 

# Copyright (c) Pymatgen Development Team. 

# Distributed under the terms of the MIT License. 

 

from __future__ import division, unicode_literals 

 

""" 

This module defines standard transformations which transforms a structure into 

another structure. Standard transformations operate in a structure-wide manner, 

rather than site-specific manner. 

All transformations should inherit the AbstractTransformation ABC. 

""" 

 

 

__author__ = "Shyue Ping Ong, Will Richards" 

__copyright__ = "Copyright 2011, The Materials Project" 

__version__ = "1.2" 

__maintainer__ = "Shyue Ping Ong" 

__email__ = "shyuep@gmail.com" 

__date__ = "Sep 23, 2011" 

 

 

import logging 

 

from pymatgen.analysis.bond_valence import BVAnalyzer 

from pymatgen.analysis.ewald import EwaldSummation, EwaldMinimizer 

from pymatgen.core.composition import Composition 

from pymatgen.core.operations import SymmOp 

from pymatgen.core.periodic_table import get_el_sp 

from pymatgen.core.structure import Structure 

from pymatgen.transformations.site_transformations import \ 

PartialRemoveSitesTransformation 

from pymatgen.transformations.transformation_abc import AbstractTransformation 

 

logger = logging.getLogger(__name__) 

 

 

class IdentityTransformation(AbstractTransformation): 

""" 

This is a demo transformation which does nothing, i.e. just returns a copy 

of the same structure. 

""" 

def apply_transformation(self, structure): 

return Structure(structure.lattice, structure.species_and_occu, 

structure.frac_coords) 

 

def __str__(self): 

return "Identity Transformation" 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return self 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "init_args": {}, 

"version": __version__, "@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class RotationTransformation(AbstractTransformation): 

""" 

The RotationTransformation applies a rotation to a structure. 

 

Args: 

axis (3x1 array): Axis of rotation, e.g., [1, 0, 0] 

angle (float): Angle to rotate 

angle_in_radians (bool): Set to True if angle is supplied in radians. 

Else degrees are assumed. 

""" 

 

def __init__(self, axis, angle, angle_in_radians=False): 

""" 

 

""" 

self._axis = axis 

self._angle = angle 

self._angle_in_radians = angle_in_radians 

self._symmop = SymmOp.from_axis_angle_and_translation( 

self._axis, self._angle, self._angle_in_radians) 

 

def apply_transformation(self, structure): 

s = structure.copy() 

s.apply_operation(self._symmop) 

return s 

 

def __str__(self): 

return "Rotation Transformation about axis " + \ 

"{} with angle = {:.4f} {}".format( 

self._axis, self._angle, 

"radians" if self._angle_in_radians else "degrees") 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return RotationTransformation(self._axis, -self._angle, 

self._angle_in_radians) 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"axis": self._axis, "angle": self._angle, 

"angle_in_radians": self._angle_in_radians}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class OxidationStateDecorationTransformation(AbstractTransformation): 

""" 

This transformation decorates a structure with oxidation states. 

 

Args: 

oxidation_states (dict): Oxidation states supplied as a dict, 

e.g., {"Li":1, "O":-2} 

""" 

 

def __init__(self, oxidation_states): 

self.oxi_states = oxidation_states 

 

def apply_transformation(self, structure): 

s = structure.copy() 

s.add_oxidation_state_by_element(self.oxi_states) 

return s 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"oxidation_states": self.oxi_states}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class AutoOxiStateDecorationTransformation(AbstractTransformation): 

""" 

This transformation automatically decorates a structure with oxidation 

states using a bond valence approach. 

 

Args: 

symm_tol (float): Symmetry tolerance used to determine which sites are 

symmetrically equivalent. Set to 0 to turn off symmetry. 

max_radius (float): Maximum radius in Angstrom used to find nearest 

neighbors. 

max_permutations (int): Maximum number of permutations of oxidation 

states to test. 

distance_scale_factor (float): A scale factor to be applied. This is 

useful for scaling distances, esp in the case of 

calculation-relaxed structures, which may tend to under (GGA) or 

over bind (LDA). The default of 1.015 works for GGA. For 

experimental structure, set this to 1. 

""" 

 

def __init__(self, symm_tol=0.1, max_radius=4, max_permutations=100000, 

distance_scale_factor=1.015): 

self.analyzer = BVAnalyzer(symm_tol, max_radius, max_permutations, 

distance_scale_factor) 

 

def apply_transformation(self, structure): 

return self.analyzer.get_oxi_state_decorated_structure(structure) 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"symm_tol": self.analyzer.symm_tol, 

"max_radius": self.analyzer.max_radius, 

"max_permutations": self.analyzer 

.max_permutations, 

"distance_scale_factor": 

self.analyzer.dist_scale_factor}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class OxidationStateRemovalTransformation(AbstractTransformation): 

""" 

This transformation removes oxidation states from a structure. 

""" 

def apply_transformation(self, structure): 

s = structure.copy() 

s.remove_oxidation_states() 

return s 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {}, "@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class SupercellTransformation(AbstractTransformation): 

""" 

The RotationTransformation applies a rotation to a structure. 

 

Args: 

scaling_matrix: A matrix of transforming the lattice vectors. 

Defaults to the identity matrix. Has to be all integers. e.g., 

[[2,1,0],[0,3,0],[0,0,1]] generates a new structure with 

lattice vectors a" = 2a + b, b" = 3b, c" = c where a, b, and c 

are the lattice vectors of the original structure. 

""" 

 

def __init__(self, scaling_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1))): 

self._matrix = scaling_matrix 

 

@staticmethod 

def from_scaling_factors(scale_a=1, scale_b=1, scale_c=1): 

""" 

Convenience method to get a SupercellTransformation from a simple 

series of three numbers for scaling each lattice vector. Equivalent to 

calling the normal with [[scale_a, 0, 0], [0, scale_b, 0], 

[0, 0, scale_c]] 

 

Args: 

scale_a: Scaling factor for lattice direction a. Defaults to 1. 

scale_b: Scaling factor for lattice direction b. Defaults to 1. 

scale_c: Scaling factor for lattice direction c. Defaults to 1. 

 

Returns: 

SupercellTransformation. 

""" 

return SupercellTransformation([[scale_a, 0, 0], [0, scale_b, 0], 

[0, 0, scale_c]]) 

 

def apply_transformation(self, structure): 

return structure * self._matrix 

 

def __str__(self): 

return "Supercell Transformation with scaling matrix " + \ 

"{}".format(self._matrix) 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

raise NotImplementedError() 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"scaling_matrix": self._matrix}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class SubstitutionTransformation(AbstractTransformation): 

""" 

This transformation substitutes species for one another. 

 

Args: 

species_map: A dict or list of tuples containing the species mapping in 

string-string pairs. E.g., {"Li":"Na"} or [("Fe2+","Mn2+")]. 

Multiple substitutions can be done. Overloaded to accept 

sp_and_occu dictionary E.g. {"Si: {"Ge":0.75, "C":0.25}}, 

which substitutes a single species with multiple species to 

generate a disordered structure. 

""" 

def __init__(self, species_map): 

self._species_map = dict(species_map) 

for k, v in self._species_map.items(): 

if isinstance(v, (tuple, list)): 

self._species_map[k] = dict(v) 

 

def apply_transformation(self, structure): 

species_map = {} 

for k, v in self._species_map.items(): 

if isinstance(v, dict): 

value = {get_el_sp(x): y for x, y in v.items()} 

else: 

value = get_el_sp(v) 

species_map[get_el_sp(k)] = value 

s = structure.copy() 

s.replace_species(species_map) 

return s 

 

def __str__(self): 

return "Substitution Transformation :" + \ 

", ".join([str(k) + "->" + str(v) 

for k, v in self._species_map.items()]) 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

inverse_map = {v: k for k, v in self._species_map.items()} 

return SubstitutionTransformation(inverse_map) 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

#convert sp_map to tuple representation to work with Mongo 

#which doesn't allow '.' in key names 

sp_map = [] 

for k, v in self._species_map.items(): 

if isinstance(v, dict): 

v = [(str(k2), v2) for k2, v2 in v.items()] 

sp_map.append((str(k), v)) 

else: 

sp_map.append((str(k), str(v))) 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"species_map": sp_map}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class RemoveSpeciesTransformation(AbstractTransformation): 

""" 

Remove all occurrences of some species from a structure. 

 

Args: 

species_to_remove: List of species to remove. E.g., ["Li", "Mn"] 

""" 

def __init__(self, species_to_remove): 

self._species = species_to_remove 

 

def apply_transformation(self, structure): 

s = structure.copy() 

for sp in self._species: 

s.remove_species([get_el_sp(sp)]) 

return s 

 

def __str__(self): 

return "Remove Species Transformation :" + ", ".join(self._species) 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"species_to_remove": self._species}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class PartialRemoveSpecieTransformation(AbstractTransformation): 

""" 

Remove fraction of specie from a structure. 

 

Requires an oxidation state decorated structure for ewald sum to be 

computed. 

 

Given that the solution to selecting the right removals is NP-hard, there 

are several algorithms provided with varying degrees of accuracy and speed. 

Please see 

:class:`pymatgen.transformations.site_transformations.PartialRemoveSitesTransformation`. 

 

Args: 

specie_to_remove: Specie to remove. Must have oxidation state E.g., 

"Li+" 

fraction_to_remove: Fraction of specie to remove. E.g., 0.5 

algo: This parameter allows you to choose the algorithm to perform 

ordering. Use one of PartialRemoveSpecieTransformation.ALGO_* 

variables to set the algo. 

""" 

 

ALGO_FAST = 0 

ALGO_COMPLETE = 1 

ALGO_BEST_FIRST = 2 

ALGO_ENUMERATE = 3 

 

def __init__(self, specie_to_remove, fraction_to_remove, algo=ALGO_FAST): 

""" 

 

""" 

self._specie = specie_to_remove 

self._frac = fraction_to_remove 

self._algo = algo 

 

def apply_transformation(self, structure, return_ranked_list=False): 

""" 

Apply the transformation. 

 

Args: 

structure: input structure 

return_ranked_list (bool/int): Boolean stating whether or not 

multiple structures are returned. If return_ranked_list is 

an int, that number of structures is returned. 

 

Returns: 

Depending on returned_ranked list, either a transformed structure 

or a list of dictionaries, where each dictionary is of the form 

{"structure" = .... , "other_arguments"} 

the key "transformation" is reserved for the transformation that 

was actually applied to the structure. 

This transformation is parsed by the alchemy classes for generating 

a more specific transformation history. Any other information will 

be stored in the transformation_parameters dictionary in the 

transmuted structure class. 

""" 

sp = get_el_sp(self._specie) 

specie_indices = [i for i in range(len(structure)) 

if structure[i].species_and_occu == 

Composition({sp: 1})] 

trans = PartialRemoveSitesTransformation([specie_indices], 

[self._frac], algo=self._algo) 

return trans.apply_transformation(structure, return_ranked_list) 

 

@property 

def is_one_to_many(self): 

return True 

 

def __str__(self): 

spec_str = ["Species = {}".format(self._specie), 

"Fraction to remove = {}".format(self._frac), 

"ALGO = {}".format(self._algo)] 

return "PartialRemoveSpecieTransformation : " + ", ".join(spec_str) 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return None 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"specie_to_remove": self._specie, 

"fraction_to_remove": self._frac, 

"algo": self._algo}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class OrderDisorderedStructureTransformation(AbstractTransformation): 

""" 

Order a disordered structure. The disordered structure must be oxidation 

state decorated for ewald sum to be computed. No attempt is made to perform 

symmetry determination to reduce the number of combinations. 

 

Hence, attempting to performing ordering on a large number of disordered 

sites may be extremely expensive. The time scales approximately with the 

number of possible combinations. The algorithm can currently compute 

approximately 5,000,000 permutations per minute. 

 

Also, simple rounding of the occupancies are performed, with no attempt 

made to achieve a target composition. This is usually not a problem for 

most ordering problems, but there can be times where rounding errors may 

result in structures that do not have the desired composition. 

This second step will be implemented in the next iteration of the code. 

 

If multiple fractions for a single species are found for different sites, 

these will be treated separately if the difference is above a threshold 

tolerance. currently this is .1 

 

For example, if a fraction of .25 Li is on sites 0,1,2,3 and .5 on sites 

4, 5, 6, 7 1 site from [0,1,2,3] will be filled and 2 sites from [4,5,6,7] 

will be filled, even though a lower energy combination might be found by 

putting all lithium in sites [4,5,6,7]. 

 

USE WITH CARE. 

 

Args: 

num_structures: Maximum number of structures to return 

mev_cutoff (float): maximum mev per atom above the minimum energy 

ordering for a structure to be returned 

symmetrized_structures (bool): Whether the input structures are 

instances of SymmetrizedStructure, and that their symmetry 

should be used for the grouping of sites. 

""" 

 

ALGO_FAST = 0 

ALGO_COMPLETE = 1 

ALGO_BEST_FIRST = 2 

 

def __init__(self, algo=ALGO_FAST, symmetrized_structures=False): 

self._algo = algo 

self._all_structures = [] 

self._symmetrized = symmetrized_structures 

 

def apply_transformation(self, structure, return_ranked_list=False): 

""" 

For this transformation, the apply_transformation method will return 

only the ordered structure with the lowest Ewald energy, to be 

consistent with the method signature of the other transformations. 

However, all structures are stored in the all_structures attribute in 

the transformation object for easy access. 

 

Args: 

structure: Oxidation state decorated disordered structure to order 

return_ranked_list (bool): Whether or not multiple structures are 

returned. If return_ranked_list is a number, that number of 

structures is returned. 

 

Returns: 

Depending on returned_ranked list, either a transformed structure 

or a list of dictionaries, where each dictionary is of the form 

{"structure" = .... , "other_arguments"} 

the key "transformation" is reserved for the transformation that 

was actually applied to the structure. 

This transformation is parsed by the alchemy classes for generating 

a more specific transformation history. Any other information will 

be stored in the transformation_parameters dictionary in the 

transmuted structure class. 

""" 

 

try: 

num_to_return = int(return_ranked_list) 

except ValueError: 

num_to_return = 1 

 

num_to_return = max(1, num_to_return) 

 

equivalent_sites = [] 

exemplars = [] 

#generate list of equivalent sites to order 

#equivalency is determined by sp_and_occu and symmetry 

#if symmetrized structure is true 

for i, site in enumerate(structure): 

if site.is_ordered: 

continue 

found = False 

for j, ex in enumerate(exemplars): 

sp = ex.species_and_occu 

if not site.species_and_occu.almost_equals(sp): 

continue 

if self._symmetrized: 

sym_equiv = structure.find_equivalent_sites(ex) 

sym_test = site in sym_equiv 

else: 

sym_test = True 

if sym_test: 

equivalent_sites[j].append(i) 

found = True 

break 

if not found: 

equivalent_sites.append([i]) 

exemplars.append(site) 

 

#generate the list of manipulations and input structure 

s = Structure.from_sites(structure) 

m_list = [] 

for g in equivalent_sites: 

total_occupancy = sum([structure[i].species_and_occu for i in g], 

Composition()) 

total_occupancy = dict(total_occupancy.items()) 

#round total occupancy to possible values 

for k, v in total_occupancy.items(): 

if abs(v - round(v)) > 0.25: 

raise ValueError("Occupancy fractions not consistent " 

"with size of unit cell") 

total_occupancy[k] = int(round(v)) 

#start with an ordered structure 

initial_sp = max(total_occupancy.keys(), 

key=lambda x: abs(x.oxi_state)) 

for i in g: 

s[i] = initial_sp 

#determine the manipulations 

for k, v in total_occupancy.items(): 

if k == initial_sp: 

continue 

m = [k.oxi_state / initial_sp.oxi_state if initial_sp.oxi_state 

else 0, v, list(g), k] 

m_list.append(m) 

#determine the number of empty sites 

empty = len(g) - sum(total_occupancy.values()) 

if empty > 0.5: 

m_list.append([0, empty, list(g), None]) 

 

matrix = EwaldSummation(s).total_energy_matrix 

ewald_m = EwaldMinimizer(matrix, m_list, num_to_return, self._algo) 

 

self._all_structures = [] 

 

lowest_energy = ewald_m.output_lists[0][0] 

num_atoms = sum(structure.composition.values()) 

 

for output in ewald_m.output_lists: 

s_copy = s.copy() 

# do deletions afterwards because they screw up the indices of the 

# structure 

del_indices = [] 

for manipulation in output[1]: 

if manipulation[1] is None: 

del_indices.append(manipulation[0]) 

else: 

s_copy[manipulation[0]] = manipulation[1] 

s_copy.remove_sites(del_indices) 

self._all_structures.append( 

{"energy": output[0], 

"energy_above_minimum": 

(output[0] - lowest_energy) / num_atoms, 

"structure": s_copy.get_sorted_structure()}) 

 

if return_ranked_list: 

return self._all_structures 

else: 

return self._all_structures[0]["structure"] 

 

def __str__(self): 

return "Order disordered structure transformation" 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return True 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"algo": self._algo}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

@property 

def lowest_energy_structure(self): 

return self._all_structures[0]["structure"] 

 

 

class PrimitiveCellTransformation(AbstractTransformation): 

""" 

This class finds the primitive cell of the input structure. 

It returns a structure that is not necessarily orthogonalized 

Author: Will Richards 

 

Args: 

tolerance (float): Tolerance for each coordinate of a particular 

site. For example, [0.5, 0, 0.5] in cartesian coordinates will be 

considered to be on the same coordinates as [0, 0, 0] for a 

tolerance of 0.5. Defaults to 0.5. 

 

""" 

def __init__(self, tolerance=0.5): 

self._tolerance = tolerance 

 

def apply_transformation(self, structure): 

""" 

Returns most primitive cell for structure. 

 

Args: 

structure: A structure 

 

Returns: 

The most primitive structure found. The returned structure is 

guaranteed to have len(new structure) <= len(structure). 

""" 

return structure.get_primitive_structure(tolerance=self._tolerance) 

 

def __str__(self): 

return "Primitive cell transformation" 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"tolerance": self._tolerance}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__} 

 

 

class PerturbStructureTransformation(AbstractTransformation): 

""" 

This transformation perturbs a structure by a specified distance in random 

directions. Used for breaking symmetries. 

 

Args: 

amplitude (float): Amplitude of perturbation in angstroms. All sites 

will be perturbed by exactly that amplitude in a random direction. 

""" 

 

def __init__(self, amplitude=0.01): 

 

self._amp = amplitude 

 

def apply_transformation(self, structure): 

s = structure.copy() 

s.perturb(self._amp) 

return s 

 

def __str__(self): 

return "PerturbStructureTransformation : " + \ 

"Amplitude = {}".format(self._amp) 

 

def __repr__(self): 

return self.__str__() 

 

@property 

def inverse(self): 

return None 

 

@property 

def is_one_to_many(self): 

return False 

 

def as_dict(self): 

return {"name": self.__class__.__name__, "version": __version__, 

"init_args": {"amplitude": self._amp}, 

"@module": self.__class__.__module__, 

"@class": self.__class__.__name__}