Это старая версия документа!


Пересчет весовых процентов оксидов на атомные проценты

Пересчет весовых процентов оксидов на атомные проценты.

Подробнее

Информация о публикации
Ссылка
Учитываемые компоненты
Выводимые компоненты
Рассчитать

Код

elements <- read.csv("constants_elements.csv",stringsAsFactors=F);
oxides <- read.csv("constants_oxides.csv",stringsAsFactors=F);

recalc.wtp_comp_to_atp <- function (wtp_data, cat_only = T, ...)
{
    
  data <- wtp_data[,grep("_wtp", names(wtp_data))];
  
  data_atp = data.frame(Name=wtp_data$Name);
  cF = rep(0, nrow(data));
  cCl = rep(0, nrow(data));
  cO = rep(0, nrow(data));


  for (wtname in names(data))
  {
  oxname <- gsub('_wtp', "", wtname);

  oxconst = subset(oxides,oxide==oxname)
  catconst = subset(elements,element==oxconst$cation) 
  anconst = subset(elements,element==oxconst$anion) 

  ddf = data.frame(data[,wtname]/(catconst$weight*oxconst$cation_count+anconst$weight*oxconst$anion_count)*oxconst$cation_count);
  names(ddf) <- c(oxconst$cation);
  data_atp = cbind(data_atp, ddf);

  anc = data[,wtname]/(catconst$weight*oxconst$cation_count+anconst$weight*oxconst$anion_count)*oxconst$anion_count;
  if(oxconst$anion=="F") {cF = cF + anc}
  if(oxconst$anion=="Cl") {cCl = cCl + anc}
  if(oxconst$anion=="O") {cO = cO + anc}
  
  }
   
  data_atp$Name <- NULL;

  if(!cat_only)
  {
    data_atp$F <- cF;
    data_atp$Cl <- cCl;
    data_atp$O <- cO;
  }
  else
  {
    data_atp$F <- NULL;
    data_atp$Cl <- NULL;
    data_atp$O <- NULL;
  }
  
  data_sum <- rowSums(data_atp);
  data_atp_ret <- rowApply('/',data_atp,data_sum);
  
  names(data_atp_ret) <- paste0(names(data_atp_ret),'_atp');
  
  return(cbind(Name=wtp_data$Name,data_atp_ret));
}
  • recalc/wtp_comp_to_atp.1452609644.txt.gz
  • Последние изменения: 2018/11/12 15:08
  • (внешнее изменение)