Пример #1
0
        def test_load_elastic_tensor(self):
            df = load_elastic_tensor()
            self.assertTrue(isinstance(df, pd.DataFrame))
            self.assertEqual(len(df.columns), 17)

            df = load_elastic_tensor(include_metadata=True)
            self.assertTrue(isinstance(df, pd.DataFrame))
            self.assertEqual(len(df.columns), 20)
        def test_load_elastic_tensor(self):
            df = load_elastic_tensor()
            self.assertTrue(isinstance(df, pd.DataFrame))
            self.assertEqual(len(df.columns), 17)

            df = load_elastic_tensor(include_metadata=True)
            self.assertTrue(isinstance(df, pd.DataFrame))
            self.assertEqual(len(df.columns), 20)
Пример #3
0
def load_tutorial_data():
    """
    Helper function to load tutorial data, loads
    the elastic tensor data from the MatMiner/MP API
    drops columns and renames the VRH K and G to
    bulk and shear modulus, rounds to 1 decimal
    point, and sets the index to the material id
    """
    data = load_elastic_tensor()
    data = data.drop(
        [
            'nsites',
            # 'space_group',
            'elastic_anisotropy',
            'structure',
            'volume',
            'G_Voigt',
            'G_Reuss',
            'K_Voigt',
            'K_Reuss',
            'compliance_tensor',
            'elastic_tensor',
            'elastic_tensor_original',
            'poisson_ratio'
        ],
        axis=1)
    data = data.rename({
        "K_VRH": "bulk_modulus",
        "G_VRH": "shear_modulus"
    },
                       axis='columns')
    data = data.round(1)
    data = data.set_index('material_id')
    return data
Пример #4
0
def test_files():
    df=load_elastic_tensor()
    df.to_csv('原始elastic数据.csv')
    print(df.columns)

    unwanted_columns=['volume','nsites','compliance_tensor','elastic_tensor','elastic_tensor_original','K_Voigt','G_Voigt','K_Reuss','G_Reuss']
    df=df.drop(unwanted_columns,axis=1)
    print(df.head())
    df.to_csv('扔掉不需要的部分.csv')
def generate_data():
    df = load_elastic_tensor()
    df.to_csv('原始elastic数据.csv')
    print(df.columns)

    unwanted_columns = [
        'volume', 'nsites', 'compliance_tensor', 'elastic_tensor',
        'elastic_tensor_original', 'K_Voigt', 'G_Voigt', 'K_Reuss', 'G_Reuss'
    ]
    df = df.drop(unwanted_columns, axis=1)
    print(df.head())
    df.to_csv('扔掉不需要的部分.csv')

    #首先使用describe获得对于数据的整体把握
    print(df.describe())
    df.describe().to_csv('general_look.csv')
    #通过观察数据发现并没有什么异常之处
    df = StrToComposition().featurize_dataframe(df, 'formula')
    print(df.head())
    df.to_csv('引入composition.csv')

    #下一步,我们需要其中一个特征化来增加一系列的特征算符
    ep_feat = ElementProperty.from_preset(preset_name='magpie')
    df = ep_feat.featurize_dataframe(
        df, col_id='composition')  #将composition这一列作为特征化的输入
    print(df.head())
    print(ep_feat.citations())
    df.to_csv('将composition特征化后.csv')

    #开始引入新的特征化算符吧
    df = CompositionToOxidComposition().featurize_dataframe(
        df, 'composition')  #引入了氧化态的相关特征
    os_feat = OxidationStates()
    df = os_feat.featurize_dataframe(df, col_id='composition_oxid')
    print(df.head())
    df.to_csv('引入氧化态之后.csv')

    #其实除了基于composition的特征之外还有很多其他的,比如基于结构的
    df_feat = DensityFeatures()
    df = df_feat.featurize_dataframe(df, 'structure')
    print(df.head())
    df.to_csv('引入结构中的密度.csv')
    print(df_feat.feature_labels())
from matminer.datasets.convenience_loaders import load_elastic_tensor

df = load_elastic_tensor()
print(df.columns)
"""
Index(['material_id', 'formula', 'nsites', 'space_group', 'volume',
       'structure', 'elastic_anisotropy', 'G_Reuss', 'G_VRH', 'G_Voigt',
       'K_Reuss', 'K_VRH', 'K_Voigt', 'poisson_ratio', 'compliance_tensor',
       'elastic_tensor', 'elastic_tensor_original'],
      dtype='object')
"""
unwanted_columns = ["volume", "nsites", "compliance_tensor", "elastic_tensor",
                    "elastic_tensor_original", "K_Voigt", "G_Voigt", "K_Reuss", "G_Reuss"]
df = df.drop(unwanted_columns, axis=1)

from matminer.featurizers.conversions import StrToComposition

df = StrToComposition().featurize_dataframe(df, 'formula')

from matminer.featurizers.composition import ElementProperty

ep_feat = ElementProperty.from_preset(preset_name="magpie")
df = ep_feat.featurize_dataframe(df, col_id='composition')

from matminer.featurizers.conversions import CompositionToOxidComposition
from matminer.featurizers.composition import OxidationStates

df = CompositionToOxidComposition().featurize_dataframe(df, "composition")

os_feat = OxidationStates()
df = os_feat.featurize_dataframe(df, "composition_oxid")