# Copyright (c) Henniggroup.
# Distributed under the terms of the MIT License.
from __future__ import division, unicode_literals, print_function
"""
Test module:
This module contains the unit tests for GASP.
"""
from gasp import general, development, variations, population, \
energy_calculators, organism_creators, objects_maker
from gasp import geometry as geo
from pymatgen.core.periodic_table import Element
import unittest
import random
import copy
import numpy as np
import os
import shutil
import tempfile
class TestIDGenerator(unittest.TestCase):
def setUp(self):
self.id_generator = general.IDGenerator()
def test_initial_id_value(self):
self.assertEqual(self.id_generator.id, 0)
def test_incrementing_value(self):
first_id = self.id_generator.make_id()
second_id = self.id_generator.make_id()
self.assertEqual(first_id + 1, second_id)
class TestMating(unittest.TestCase):
def setUp(self):
mating_params = {'fraction': 0.1}
self.mating = variations.Mating(mating_params)
# get the current working directory and make a copy of it
self.starting_cwd = copy.deepcopy(os.getcwd())
# make a temporary directory and move into it
self.temp_dir = tempfile.mkdtemp()
os.chdir(self.temp_dir)
def tearDown(self):
# move back to the original working directory
os.chdir(self.starting_cwd)
# delete the temporary directory
shutil.rmtree(self.temp_dir)
def test_double_parent(self):
# make a cell to test
species = [Element('Cu')]
coords = [[0.5, 0.5, 0.5]]
lattice = [[1, 0, 0], [0, 2, 0], [0, 0, 3]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = copy.deepcopy(cell.lattice.volume)
# test with bulk geometry
geometry = geo.Bulk()
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(2*old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a different lattice
lattice = [[3, 0, 0], [0, 1, 0], [0, 0, 2]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = copy.deepcopy(cell.lattice.volume)
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(2*old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a different lattice
lattice = [[3, 0, 0], [0, 2, 0], [0, 0, 1]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = copy.deepcopy(cell.lattice.volume)
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(2*old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a random lattice
lattice = [
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)],
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)],
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)]]
cell = general.Cell(lattice, species, coords)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = copy.deepcopy(cell.lattice.volume)
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test with sheet geometry
geometry = geo.Sheet({'shape': 'sheet'})
lattice = [[1, 0, 0], [0, 2, 0], [0, 0, 3]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = cell.lattice.volume
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(2*old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a different lattice
lattice = [[3, 0, 0], [0, 1, 0], [0, 0, 2]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = cell.lattice.volume
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(2*old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a different lattice
lattice = [[3, 0, 0], [0, 2, 0], [0, 0, 1]]
cell = general.Cell(lattice, species, coords)
old_lattice_lengths = copy.deepcopy(cell.lattice.abc)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = cell.lattice.volume
self.mating.double_parent(cell, geometry)
self.assertEqual(round(cell.lattice.a, 5),
round(old_lattice_lengths[0], 5))
self.assertEqual(round(cell.lattice.b, 5),
round(2*old_lattice_lengths[1], 5))
self.assertEqual(round(cell.lattice.c, 5),
round(old_lattice_lengths[2], 5))
self.assertEqual(round(cell.lattice.volume, 5), round(2*old_volume, 5))
self.assertEqual(cell.num_sites, 2*old_num_atoms)
# test a cell with a random lattice
lattice = [
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)],
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)],
[random.uniform(-5, 5), random.uniform(-5, 5),
random.uniform(-5, 5)]]
cell = general.Cell(lattice, species, coords)
old_num_atoms = copy.deepcopy(cell.num_sites)
old_volume = copy.deepcopy(cell.lattice.volume)
self.mating.double_parent(cell, geometr
没有合适的资源?快使用搜索试试~ 我知道了~
用于与 GULP、LAMMPS 和 VASP 接口的结构和相位预测的遗传算法_python_代码_下载
共56个文件
py:21个
rst:7个
yaml:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 69 浏览量
2022-06-18
23:24:45
上传
评论
收藏 539KB ZIP 举报
温馨提示
GASP 是一种用 Python 编写的用于结构和相位预测的遗传算法,并与GULP、LAMMPS和VASP接口。它可以搜索团簇、二维材料、线材和块状材料的结构,并进行固定成分和相图搜索。
资源推荐
资源详情
资源评论
收起资源包目录
GASP-python-master.zip (56个子文件)
GASP-python-master
.gitignore 249B
gasp
geometry.py 22KB
post_processing
__init__.py 0B
plotter.py 6KB
objects_maker.py 34KB
development.py 39KB
tests
test.py 77KB
__init__.py 0B
general.py 34KB
energy_calculators.py 31KB
parameters_printer.py 14KB
__init__.py 0B
scripts
plot_phase_diagram.py 402B
replace_tabs.py 575B
plot_progress.py 387B
run.py 24KB
plot_system_size.py 403B
population.py 32KB
variations.py 56KB
organism_creators.py 28KB
README.rst 6KB
docs
_config.yml 26B
make.bat 8KB
conf.py 12KB
index.rst 424B
usage.md 61KB
gasp.rst 1KB
Makefile 7KB
examples
Au_clusters_lammps
in.min 344B
README.rst 2KB
ga_input.yaml 322B
calllammps 363B
Au_u3.eam 36KB
icosahedron.png 125KB
Al-ZrAl-CuAl_pd_lammps
ZrCuAl.eam.alloy 284KB
in.min 436B
ref_states
POSCAR.AlZr 233B
POSCAR.Al 161B
POSCAR.AlCu 233B
README.rst 2KB
ga_input.yaml 283B
calllammps 363B
partial_phase_diagram.png 33KB
SiO2_2D_gulp
README.rst 2KB
ga_input.yaml 199B
callgulp 353B
potential_file 621B
header_file 43B
Au_wires_lammps
in.min 414B
wire.png 121KB
README.rst 2KB
ga_input.yaml 387B
calllammps 363B
Au_u3.eam 36KB
LICENSE.md 1KB
setup.py 1KB
共 56 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
- MicroMsg.xlsx
- 88-520告白(520气球).zip
- HTML+CSS+JS精品网页模板H126.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功